(Variable file contains array of URL .json files). One file in subdirectories contains:
[ {"name": "John"} ]
Then I get common file get.json who contains all files from subdirectories in structure (yeap, I know it's not a valid JSON):
[ {"name": "John"} ]
[ {"name": "Sergei"} ]
I want get this file in this structure:
[ {name: "John"}, {name: "Sergei"} ]
My code
recursive(`${dirPath}`, ['delete.json', 'put.json'], function (err, file) {
const write = fs.createWriteStream(`${dirPath}/get.json`);
file.forEach(item => {
fs.createReadStream(item).pipe(write);
})
write.on('finish', () => {
fs.createReadStream(`${dirPath}/get.json`).pipe(res);
})
});
[ {name: "John"}] [ {name: "Sergei"}]is not valid JSON. Is your sample data wrong, or are you asking how to parse this non-standard file format?[ {name: "John"}] [ {name: "Sergei"}]- you claim this is JSON ... it isn't even close to JSON - if it were JSON, it'd look like[[ {"name": "John"}],[ {"name": "Sergei"}]]or[ {"name": "John"}, {"name": "Sergei"} ]JSON.parse, then get the object in index0and finally push it into an array.