8 ms·
I regularly use jq to summarize the structure of big JSON blobs, using the snippet written here (I alias it to "jq-structure"): https://github.com/stedolan/jq/i
by ReidZB 6y ago
I regularly use jq to summarize the structure of big JSON blobs, using the snippet written here (I alias it to "jq-structure"): https://github.com/stedolan/jq/issues/243#issuecomment-48470943 https://github.com/stedolan/jq/issues/243#issuecomment-48470...
For example, against the public AWS IP address JSON document, it produces an output like
$ curl -s 'https://ip-ranges.amazonaws.com/ip-ranges.json' | jq -r '[path(..)|map(if type=="number" then "[]" else tostring end)|join(".")|split(".[]")|join("[]")]|unique|map("."+.)|.[]'
.
.createDate
.ipv6_prefixes
.ipv6_prefixes[]
.ipv6_prefixes[].ipv6_prefix
.ipv6_prefixes[].network_border_group
.ipv6_prefixes[].region
.ipv6_prefixes[].service
.prefixes
.prefixes[]
.prefixes[].ip_prefix
.prefixes[].network_border_group
.prefixes[].region
.prefixes[].service
.syncToken
This plus some copy/paste has worked pretty well for me.
- jandrese 6y agoWow, it looks so easy, why doesn't everybody do that? /s That jq query looks like an unwise Perl one-liner.
- ReidZB 6y agoYes, it is arguably an unholy contrivance, but someone's already written it, and invoking it as a shell alias or likewise is both easy and useful. $ jq-structure my-file.json
- ci5er 6y agoHey! That's kind of how how I use the CLI (API?) at AWS. It works pretty well! And fortunately (for me), not too much thinking involved. BTW: I have a D3 front-end dashboard/console for the app (not admin) that makes this a little bit harder, but D3 is pretty organized (and well-documented), if you can figure out what you are trying to do with it.