Skip to content

Instantly share code, notes, and snippets.

@mirskiy
Created April 2, 2017 16:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mirskiy/773bb250470250ecea1453f0f03c00b4 to your computer and use it in GitHub Desktop.
Save mirskiy/773bb250470250ecea1453f0f03c00b4 to your computer and use it in GitHub Desktop.
Diff json with vimdiff
# Add this to your .bashrc or .bash_aliases
jdiff() {
# Diff json files faster
# Uses python json.dump with sort_keys=True to fix ordering, then vimdiff
if [[ $# -ne 2 ]]; then
echo "syntax: jdiff file1 file2"
return
fi
py3 -c "import json; json.dump(json.load(open('$1')), open('/tmp/jdiff.1', 'w'), indent=4, sort_keys=True)"
py3 -c "import json; json.dump(json.load(open('$2')), open('/tmp/jdiff.2', 'w'), indent=4, sort_keys=True)"
vimdiff /tmp/jdiff.{1,2}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment