Reputation: 1130
I have a json file like this:
[{
"path": "p1"
"title": "t1"
"tags": ["tags1"]
},
{
"path": "p2"
"title": "t2"
"tags": ["tags1", "tag2"]
},
{
"path": "p3"
"title": "t3"
"tags": ["tags2"]
}
]
and I would like to filter (using jq
) the value based on tags and get the title as output.
For instance, I would filter all the values that have tags1(and the output would be t1
and t2
).
How can I do that ?
Thank you for your answers.
P.S. : I found this question : How to filter an array of objects based on values in an inner array with jq? that almost have the answer but I was not able to adapt it.
Upvotes: 1
Views: 175
Reputation: 116640
After rectifying the JSON input, the following filter produces the output shown below:
.[] | select( .tags | index("tags1") ) | .title
Output:
"t1"
"t2"
Upvotes: 1