json1 = {
"color": "#101017",
"fontSize": "15px",
"h1": {
"color": "#101017",
"fontSize": "32px"
}
}
json2 = {
"h1": {
"color": "blue"
}
}
And output should be
json = {
"color": "#101017",
"fontSize": "15px",
"h1": {
"color": "blue",
"fontSize": "32px"
}
}
I was trying to merge two json where second one overrides the first one with a native way in javascript.
2
Answers
These "JSON objects" you posted can be treated as JavaScript objects, hence we could write a simple object merging function. Note that this function will merge any first child objects inside the object properties (like in your example), but if you make even more further child objects it will not work properly.
Something like this, maybe?