Skip to content

Instantly share code, notes, and snippets.

@fernandoacorreia
Last active November 5, 2024 16:18
Show Gist options
  • 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