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

In jq, how to select the desired properties at all levels?

$
0
0

It seems a pretty basic need, but I can't find it in the tutorial

Imagine we got an object like:

{"data":[  {"prop1":"a", "prop2":"b", "prop3":"c", "prop4":"d", "nestedprops":{"nestedprop1":"A","nestedprop2":"B"} },  {"prop2":"b", "prop3":"c", "nestedprops":{"nestedprop1":"A"}},  {"prop3":"c"}]}

I just want the exact same json, but filtering out prop3,prop4 and nestedprop2,or in other words, I want to filter in the whole tree for prop1, prop2 and nestedprop1

{"data":[  {"prop1":"a", "prop2":"b", "nestedprops":{"nestedprop1":"A"} },  {"prop2":"b", "nestedprops":{"nestedprop1":"A"}},  {}]}

I'm trying with jq '.data[] | {prop1,prop2,nestedprops:{nestedprop1}}' and the like but I can't find it


Viewing all articles
Browse latest Browse all 526

Trending Articles



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