Skip to content

Commit

Permalink
Merge pull request #15 from Shirtpantswallet/smart-quoting
Browse files Browse the repository at this point in the history
  • Loading branch information
reegnz authored Jul 26, 2022
2 parents 890345e + 42f4617 commit 5a24091
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions bin/jq-paths
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,14 @@
JQ_REPL_JQ="${JQ_REPL_JQ:-jq}"
$JQ_REPL_JQ -r '
[
path(..) | map(select(type == "string") // "[]")
| join(".")
] | sort | unique | .[] | split(".[]") | join("[]") | "." + .
path(..) |
map(
# use generic object index syntax if key contains non-alphanumeric characters or starts with a digit
select(type == "string" and (test("[^a-zA-Z0-9_]") or test("^[0-9]"))) |= "[\"" + . + "\"]"
) |
map(
# numbers are assumed to be array indexes only
select(type == "number") |= "[]"
) | join(".")
] | sort | unique | .[] | split(".[") | join("[") | "." + .
'

0 comments on commit 5a24091

Please sign in to comment.