Editing json files inline for non technical people could be challening and error prone, therefor we have opted to convert json files to flat file formats comprising of key value, the following script can convert a javascript object to such format:
var o = {
foo:"bar",
arr:[1,2,3],
subo: {
foo2:"bar2"
}
};
function traverse(o,keyPath,lines) {
for (var key in o) {
keyPath = `${keyPath}_${key}`;
if (o[key] !== null && typeof(o[key])=="object") {
//going one step down in the object tree!!
traverse(o[key],keyPath,lines);
}
else
{
lines.push(`${keyPath.replace(/(^\_+|\_+$)/mg, '')}=${o[key]}`);
}
}
}
let lines = [];
traverse(o,'',lines);
console.log(lines);
and the output:
'foo=bar',
'foo_arr_0=1',
'foo_arr_0_1=2',
'foo_arr_0_1_2=3',
'foo_arr_subo_foo2=bar2'