Selecting entries of a sub array
Selecting entries of a sub array
I have json that looks like:
"base": "abc",
"members" : [
"fn": "maurice", "ln": "hickey",
"fn": "john", "ln": "smith",
"fn": "robin", "ln": "smith",
...
],
"date": "2018-08-26"
I am trying to write a jq filter to give me the same schema output but with only a subset of the members array e.g. all the "smith"s
"base": "abc",
"members" : [
"fn": "john", "ln": "smith",
"fn": "robin", "ln": "smith"
],
"date": "2018-08-26"
Any pointers would be appreciated.
Hi Chris - thanks for responinding, I am specifically looking for a jq (stedolan.github.io/jq) filter as a solution.
– Maurice1408
Aug 26 at 16:16
1 Answer
1
This gets the desired output.
jq '.members |= map(select(.ln == "smith"))'
It updates .members, selecting only objects with .ln == smith
Thank you very much!
– Maurice1408
Aug 27 at 7:41
By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.
Are you specifically looking for a jquery filter or can you use a JavaScript/es6 filter?
– Chris Maggiulli
Aug 26 at 15:30