1

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.

1 Answer 1

1

After rectifying the JSON input, the following filter produces the output shown below:

.[] | select( .tags | index("tags1") ) | .title

Output:

"t1"
"t2"
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.