Skip to content

Instantly share code, notes, and snippets.

@JoshuaGross
Last active December 11, 2015 02:09
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save JoshuaGross/800c7f94899f928443fc to your computer and use it in GitHub Desktop.
Save JoshuaGross/800c7f94899f928443fc to your computer and use it in GitHub Desktop.
Sort JSON to make it easier to diff two JSON blobs by normalizing whitespace, alphabetization of dictionaries.
# Install:
npm install -g sort-json
# Put this in your ~/.profile, and then:
# cat something.json | normalize_json
alias normalize_json="node -e 'var s = \"\"; process.stdin.on(\"data\", function (d) { s += d.toString(); }); process.stdin.resume(); process.on(\"exit\", function() { console.log(JSON.stringify(require(\"sort-json\")(JSON.parse(s)), null, 2)); });'"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment