josephburnett / jd

JSON diff and patch
MIT License
826 stars 38 forks source link

Output only changed arrays #51

Closed eojjn closed 1 year ago

eojjn commented 1 year ago

Hello!

I'm looking for a way to output only the changed arrays after comparing two files. Am I missing something or does jd only allow for a merged output? I want to retain the structure of the file but reduce it down to only the changed data.

josephburnett commented 1 year ago

I think that the JSON Merge format is what you're after.

Given these two inputs: {"bar":[4,5,6],"foo":[1,2,3]} and {"bar":[4,5,6],"foo":[1,2,7,3]} a merge diff would look like this:

{"foo":[1,2,7,3]}

That's just the part that changed.

You can output the diff in merge format with the -f merge option. E.g. jd -f merge a.json b.json.

Does that answer your question?