1

Currently I use ediff a lot for diffing all sorts of text files. I also use it for looking at diffs between JSON files. The problem is that a lot of differences appear which are semantically irrelevant.

e.g. This snippet:

{
  alice: "Springs",
  bob: "4 apples"
}

Is semantically the same as this one since the order of keys in a JSON object does not matter (and cannot even be assumed to be well-defined):

{
  bob: "4 apples",
  alice: "Springs"
}

Obviously, however the two files are different on a plain text basis so if I look at it in ediff, I'm likely to see noise I don't care about. Is there a way/tool/technique for filtering this out?

1 Answer 1

1

I don’t have a complete solution for you, but you can run the json through jq --sort-keys to eliminate this type of unimportant difference. You might combine this with git diff --textconv, or perhaps ediff has a similar text conversion feature. You might just wrap it up in a shell script and set ediff-diff-program to that script. Note however that a diff modified in this fashion will be suitable for viewing but not for applying, so some ediff features might not work.

1
  • That'll work. Thanks. --sort-keys was the missing piece I didn't know. May 5 at 10:32

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.