Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save senhalil/fd5e06913523cb9d45b3123ebd186573 to your computer and use it in GitHub Desktop.
Save senhalil/fd5e06913523cb9d45b3123ebd186573 to your computer and use it in GitHub Desktop.
git diff -- use json_xs to pretty-print the json before diffing it
sudo apt-get install libjson-xs-perl
echo "*.json diff=json" >> ~/.gitattributes
git config --global core.attributesfile ~/.gitattributes
git config --global diff.json.textconv "json_xs -e \"print JSON::XS->new->utf8->pretty->canonical->encode(\\\$_)\" -t none < \"\$1\""
@senhalil
Copy link
Author

senhalil commented Feb 1, 2022

json_xs doesn't expose the sorting option in the command like utility so to have a consistent diff experience, one needs to use -e flag to manually encode/pretty-print the json.

json_xs is 2x faster than jq and about facter than json_pp

@senhalil
Copy link
Author

[diff "json"]
	textconv = json_xs -e \"print JSON::XS->new->utf8->pretty->canonical->encode(\\$_)\" -t none < \"$1\"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment