Skip to content

Instantly share code, notes, and snippets.

@jen6
Created February 26, 2021 05:27
Show Gist options
  • Save jen6/ab27f763c028f94f084fe6c94329a057 to your computer and use it in GitHub Desktop.
Save jen6/ab27f763c028f94f084fe6c94329a057 to your computer and use it in GitHub Desktop.
AWESOME jq
# flatten json
jq '. as $in
| reduce leaf_paths as $path ({};
. + { ($path | map(tostring) | join(".")): $in | getpath($path) })' target.json
# un-flatten json
jq 'reduce to_entries[] as $kv ({}; setpath($kv.key|split("."); $kv.value))' ./target.json
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment