I have to merge 2 json files and need to preserve a string in one of the files:
"weeks": "weeks\u00a0days"
The \u00a0
after the merge always change to space: "weeks": "weeks days"
.
I want it to stay as: "weeks": "weeks\u00a0days"
some code:
//merge.js
const fs = require('fs');
const test1 = fs.readFileSync('./test1.json', 'utf8');
const test2 = fs.readFileSync('./test2.json', 'utf8');
const merge = (obj1, obj2) =>
JSON.stringify({ ...JSON.parse(obj1), ...JSON.parse(obj2) }, null, 4);
const saveFile = (fileName, obj1, obj2) => {
fs.writeFile(`${__dirname}/${fileName}`, merge(obj1, obj2), err => {
if (err) throw err;
console.log(`The file ${fileName} has been saved!`);
});
};
saveFile('testFinal.json', test1, test2);
test1.json
{
"link": {
"about": "About",
"version": "version"
},
"items": {
"siteId": "Site ID",
"siteName": "Site name",
"siteType": "Site type",
"weeks": "weeks\u00a0days"
}
}
test2.json
{
"features": {
"activateFeatures": "Activate features",
"confirmation": "Confirmation",
"hardware": "Hardware",
"existingHardware": "Existing hardware",
"emailLicense": "Email license",
"downloadLicense": "Select quantity"
}
}
please help