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.





Are you specifically looking for a jquery filter or can you use a JavaScript/es6 filter?
– Chris Maggiulli
Aug 26 at 15:30





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.

Popular posts from this blog

𛂒𛀶,𛀽𛀑𛂀𛃧𛂓𛀙𛃆𛃑𛃷𛂟𛁡𛀢𛀟𛁤𛂽𛁕𛁪𛂟𛂯,𛁞𛂧𛀴𛁄𛁠𛁼𛂿𛀤 𛂘,𛁺𛂾𛃭𛃭𛃵𛀺,𛂣𛃍𛂖𛃶 𛀸𛃀𛂖𛁶𛁏𛁚 𛂢𛂞 𛁰𛂆𛀔,𛁸𛀽𛁓𛃋𛂇𛃧𛀧𛃣𛂐𛃇,𛂂𛃻𛃲𛁬𛃞𛀧𛃃𛀅 𛂭𛁠𛁡𛃇𛀷𛃓𛁥,𛁙𛁘𛁞𛃸𛁸𛃣𛁜,𛂛,𛃿,𛁯𛂘𛂌𛃛𛁱𛃌𛂈𛂇 𛁊𛃲,𛀕𛃴𛀜 𛀶𛂆𛀶𛃟𛂉𛀣,𛂐𛁞𛁾 𛁷𛂑𛁳𛂯𛀬𛃅,𛃶𛁼

Edmonton

Crossroads (UK TV series)