I have a JSON
version of a DOM
tree and I want keep only the difference between pages (remove nav footer ...)
Example:
const a = {
id: '1',
child: [
{
id: '2',
child: [{id: '1'}, {id: '2'}]
},
{
id: '3',
child: [{id: '1'}, {id: '5'}]
}
]
};
And
const b = {
id: '1',
child: [
{
id: '2',
child: [{id: '1'}, {id: '4'}]
},
{
id: '3',
child: [{id: '1'}, {id: '4'}]
}
]
};
With a function
diff(a, b)
This result
{
id: '1',
child: [
{
id: '2',
child: [{id: '2'}]
},
{
id: '3',
child: [{id: '5'}]
}
]
}
I created this based on recursive function
const diff = (a, b) => {
if (Array.isArray(a)) {
}
if (typeof a === 'object') {
// ...
extract(a.child, b.child);
}
}
How do I do this? Is there an npm
package? or with JSON
Path? I want to create a function that remove the equal 'parts' between two JSON
files with the output of the function having the same structure, but without the 'equal parts' only difference.