Skip to content

Instantly share code, notes, and snippets.

@fernandoacorreia
Last active March 21, 2023 03:06
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save fernandoacorreia/4b67a41bbe227654868df5eb3ca311d7 to your computer and use it in GitHub Desktop.
Save fernandoacorreia/4b67a41bbe227654868df5eb3ca311d7 to your computer and use it in GitHub Desktop.
#!/bin/bash
#
# Outputs JSON paths.
#
# Based on https://news.ycombinator.com/item?id=20264654
#
# Usage:
# curl -s https://raw.githubusercontent.com/sitepoint-editors/json-examples/master/src/db.json | ./jsonpaths
jq -r --stream '
select(length > 1)
| (
.[0] | map(
if type == "number"
then "[" + tostring + "]"
else "." + .
end
) | add
) + " = " + (.[1] | @json)
'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment