Skip to content

Instantly share code, notes, and snippets.

@murrahjm
Created October 9, 2020 15:38
Show Gist options
  • Save murrahjm/14dbf530f929f7b21732ee3a41402f88 to your computer and use it in GitHub Desktop.
Save murrahjm/14dbf530f929f7b21732ee3a41402f88 to your computer and use it in GitHub Desktop.
using jq to sort two json files for comparison
jq --argfile a file1.json -n 'def post_recurse(f): def r: (f | select(. != null) | r), .; r; def post_recurse: post_recurse(.[]?); ($a | (post_recurse | arrays) |= sort)' > fmt_file1.json
jq --argfile a file2.json -n 'def post_recurse(f): def r: (f | select(. != null) | r), .; r; def post_recurse: post_recurse(.[]?); ($a | (post_recurse | arrays) |= sort)' > fmt_file2.json
diff -ZEB <(jq -S . fmt_file1.json) <(jq -S . fmt_file2.json))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment