serhii.net

In the middle of the desert you can say anything you want

13 Mar 2023

json diff with jq, also: side-by-side output

Websites

There are online resources:

CLI

SO thread1 version:

diff <(jq --sort-keys . A.json) <(jq --sort-keys . B.json)

Wrapped it into a function in my .zshrc:

jdiff() {
	diff <(jq --sort-keys . "$1") <(jq --sort-keys . "$2")
}

Side-by-side output

vimdiff is a thing and does this by default!

Otherwise2 diff has the parameters -y, and --suppress-common-lines is useful.

This led to jdiff’s brother jdiffy:

jdiffy() {
	diff -y --suppress-common-lines <(jq --sort-keys . "$1") <(jq --sort-keys . "$2") 
}

Other

git diff --no-index allows to use git diff without the thing needing to be inside a repo. Used it heavily previously for some of its fancier functions. Say hi to gdiff:

gdiff() {
	git diff --no-index "$1" "$2"
}
Nel mezzo del deserto posso dire tutto quello che voglio.