I want to create multiple JSON files from an array.
Array :
[{
"Reference": "Registration",
"langkey": "REG_LBL",
"English": "Company Registration",
"Japanese": "会社登録"
}, {
"Reference": "Registration",
"langkey": "INFO_LBL",
"English": "Company Information",
"Japanese": "会社情報"
}]
I need to create two JSON files name English and Japanese(it will be dynamic) from above array.
Desired Output
English.json
{
'INFO_LBL' : 'Company Information',
'REG_LBL':'Company Registration'
}
Japanese.json
{
'INFO_LBL' : '会社情報',
'REG_LBL':'会社情報'
}
Code
for (var i = 0; i < data.length; i++) {
var obj = data[i];
for (var key in obj) {
if (key !=='Reference' && key !== 'langkey' ) {
//{'REG_LBL':'Company Registration'}
objects[obj['langkey']] = obj[key];
fs.writeFileSync('lang/' + langkey + '.json', JSON.stringify(objects, null, 2), { encoding: 'utf8' }, function (err) {
if (err)
{ throw err; }
console.log("completed")
});
}
}
}
I am ale to create two JSON files but the content is overwritten by another.Please help to resolve this?

langKey?