Page 1 of 1

JSON merger

Posted: Thu Feb 16, 2023 3:07 pm
by Krzysztof Mycek
Hi.
I need to merge two JSON file in one.
Does anyone have a solution for how to do this on Switch?

Re: JSON merger

Posted: Fri Feb 17, 2023 9:03 am
by freddyp
Are the two JSONs each in a dataset? Are they in the same folder? As this in the "Node.js scripting" section, perhaps this is what you are looking for:

Code: Select all

let json1 = JSON.parse(fs.readFileSync(pathToFirstJSONFile).toString());
let json2 = JSON.parse(fs.readFileSync(pathToSecondJSONFile).toString());
let newJson = { obj1:json1, obj2:json2 };
//and if the new JSON has to be saved into a new file:
fs.writeFileSync(pathToNewJSON, JSON.stringify(newJson));

Re: JSON merger

Posted: Fri Feb 17, 2023 10:09 am
by Krzysztof Mycek
Thank You Freddy. Thats it!