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

jq: how to filter an array of objects based on values in an inner array?

$
0
0

Given this input:

[  {"Id": "cb94e7a42732b598ad18a8f27454a886c1aa8bbba6167646d8f064cd86191e2b","Names": ["condescending_jones","loving_hoover"    ]  },  {"Id": "186db739b7509eb0114a09e14bcd16bf637019860d23c4fc20e98cbe068b55aa","Names": ["foo_data"    ]  },  {"Id": "a4b7e6f5752d8dcb906a5901f7ab82e403b9dff4eaaeebea767a04bac4aada19","Names": ["jovial_wozniak"    ]  },  {"Id": "76b71c496556912012c20dc3cbd37a54a1f05bffad3d5e92466900a003fbb623","Names": ["bar_data"    ]  }]

I'm trying to construct a filter with jq that returns all objects with Ids that do not contain "data" in the inner Names array, with the output being newline-separated. For the above data, the output I'd like is:

cb94e7a42732b598ad18a8f27454a886c1aa8bbba6167646d8f064cd86191e2ba4b7e6f5752d8dcb906a5901f7ab82e403b9dff4eaaeebea767a04bac4aada19

I think I'm somewhat close with this:

(. - select(.Names[] contains("data"))) | .[] .Id

but the select filter is not correct and it doesn't compile (get error: syntax error, unexpected IDENT).


Viewing all articles
Browse latest Browse all 657

Trending Articles