Quantcast
Channel: Active questions tagged jq - Stack Overflow
Viewing all articles
Browse latest Browse all 527

jq: Getting two levels of keys

$
0
0

I have some json data that looks like:

{"p": {"d": {"a" : {"r": "foo","g": 1      },"b": {"r": "bar","g": 2      }    },"c": {"e": {"r": "baz","g": 1      }    },    ...  }}

I want something like:

{"d": [ "a","b"  ],"c": ["e"  ]}

I can get the list of keys on the first level under "p" with jq '.p|keys', and the structure and keys on the second level with jq '.p|map(.|keys)', but I can't figure out how to combine it.


Viewing all articles
Browse latest Browse all 527

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>