MHN
Add a comment on Hacker News →
1 of 73 comments
  1. I use this in my `~/.jq` when I have a problem like this.

        def flat_json_keys:
            [leaf_paths as $path | {"key": $path | map(if (type=="string") then (if (test("([?:\\W]+)")) then "['"+.+"']"  else . end) else "["+tostring+"]" end) | join(".") | gsub(".\\[";"[") , "value": getpath($path)}] | from_entries;
    
        def ukeys:
            keys_unsorted;
    
    Use like so:

        cat wat.json | jq flat_json_keys