We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
These are my source and target objects and my result of a detailed diff. Shouldn't the deleted property contain, field3?
$ node app.js { "a": [ { "field1": "value1", "field2": "value2", "field3": "value3" } ], "b": [ { "field1": "value1", "field2": "value2" } ], "result": { "added": {}, "deleted": { "0": {} }, "updated": {} } }
The text was updated successfully, but these errors were encountered:
Hey @JohnGrantPGA I suspect that the issue is because the difference between a and b is being converted into JSON with JSON.stringify.
JSON.stringify
undefined is not supported in JSON, so any key/ value pairing that is undefined will be filtered out when using JSON.stringify.
undefined
What you could do instead is supply a function to JSON.stringify(obj, fn) to convert any undefined values into something of your choosing 😄.
JSON.stringify(obj, fn)
Heres an example that converts undefined values to null:
null
function replacer(key, value) { if (value == undefined) { return null; } return value; } const a = [{ "field1": "value1", "field2": "value2", "field3": "value3" }]; const b = [{ "field1": "value1", "field2": "value2" }]; const difference = detailedDiff(a, b); console.log(JSON.stringify(difference, replacer)); // {"added":{},"deleted":{"0":{"field3":null}},"updated":{}}
Sorry, something went wrong.
Hi Matt,
Thanks for the quick response! You're spot on. I incorporated your suggestions. Thank you. :)
No branches or pull requests
These are my source and target objects and my result of a detailed diff. Shouldn't the deleted property contain, field3?
The text was updated successfully, but these errors were encountered: