const input = `
bars Accommodation and hospitality Bars Horeca
artists Writers and performers Artiest Creatieve beroepen
`;
const lines = input.split('\n').filter(line => line)
const output = {};
lines.forEach(line => {
const [lob_sub_en, lob_en, lob_sub_nl, lob_nl] = line.split('\t');
const sector = lob_en.toLowerCase();
const subsector = lob_sub_en.toLowerCase();
if (lob_sub_nl !== '' && lob_sub_nl !== '-') {
if (!output[sector]) {
output[sector] = {
value: sector,
description: lob_nl,
children: [],
};
}
output[sector].children.push({
value: subsector,
description: lob_sub_nl
})
}
});
const array = Object.keys(output).map(key => output[key]);
exports.endpoint = function(request, response) {
response.end(JSON.stringify(array, null, 2));
}