Skip to content
New issue

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

Showing difference between two json objects #1160

Closed
arynaq opened this issue Jul 11, 2018 · 3 comments
Closed

Showing difference between two json objects #1160

arynaq opened this issue Jul 11, 2018 · 3 comments
Labels
kind: question solution: proposed fix a fix for the issue has been proposed and waits for confirmation

Comments

@arynaq
Copy link

arynaq commented Jul 11, 2018

I cannot figure out how I would go about doing this.

I looked into the patch function and thought about applying it to a default state of the object but suppose a key is set to boolean true while the default is false but the two objects don't differ in this key then applying the patch to the default and looking at the default would indicate this value has changed to false.

Essentially I just want a diff with minimal extra tooling.

@nlohmann
Copy link
Owner

Have you tried the diff function?

@nlohmann nlohmann added kind: question solution: proposed fix a fix for the issue has been proposed and waits for confirmation labels Jul 12, 2018
@arynaq
Copy link
Author

arynaq commented Jul 12, 2018

Ah good call, this was towards the end of the work day as I was despairing 👍
So the the diff function returns me a patch object with json pointers, I assume I can then look at the pointers to see which specific keys have changed.

I will try and paste the solution here.

@arynaq
Copy link
Author

arynaq commented Jul 12, 2018

::diff was what I needed, thank you. I ended up just writing parts of the object that the diff had an op for to file, I had to parse the json path
{ "op": "replace", "path": "/XX/YY/0/centerFrequencyInHz", "value": 9933743300.0 },

To create the nested structure with {"XX" : {"YY": [{"centerFrequencyInHz" : 9933743300.0 }]}}
but this is fine, I assume there isn't much need for the library to provide something like common(left, right, patch) which would output that directly using the patch to erase everything else.

@arynaq arynaq closed this as completed Jul 12, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind: question solution: proposed fix a fix for the issue has been proposed and waits for confirmation
Projects
None yet
Development

No branches or pull requests

2 participants