JSON merger

Post Reply
Krzysztof Mycek
Member
Posts: 30
Joined: Tue Mar 03, 2020 11:28 am

JSON merger

Post 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?
freddyp
Advanced member
Posts: 1022
Joined: Thu Feb 09, 2012 3:53 pm

Re: JSON merger

Post 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));
Krzysztof Mycek
Member
Posts: 30
Joined: Tue Mar 03, 2020 11:28 am

Re: JSON merger

Post by Krzysztof Mycek »

Thank You Freddy. Thats it!
Post Reply