I've been stuck for hours, and I need your help.
The requirement is this.
Having two JSON objects, one is always the source
and has all the data we need.
Second JSON object does not contain all data from source
The requirement:
This is the source JSON object.
{
"lang": "en",
"global": {
"clear_search": "Clear Search",
"filter": "Filter",
"projects": {
"sort_projects": "Sort projects by"
},
},
}
And this is the second object (NOTE: First object always contains more data):
{
"lang": "de",
"global": {
"clear_search": "Suche löschen",
"filter": "Filter",
},
}
I need to:
- Find difference between the
source
and object 2 - Update the difference, from
source
to object 2 - If property of the
source
is an Object, loop through it, which means if it's nested I need to loop through it, (recursion). If keys are the same, but values are not, keep the keys but use the object 2 value.
Result:
{
"lang": "de",
"global": {
"clear_search": "Suche löschen",
"filter": "Filter",
"projects": {
"sort_projects": "Sort projects by"
},
},
}
Thank you for checking this out, I kindly ask you not to post code with the variable names, like x
or _
.