Forked from Ricket/gist:78bcd681db86bcbb134558428c4c6cb4
Last active
October 3, 2023 11:47
-
-
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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\"" |
Author
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
json_xsdoesn't expose the sorting option in the command like utility so to have a consistent diff experience, one needs to use-eflag to manually encode/pretty-print the json.json_xsis 2x faster thanjqand about facter thanjson_pp