0

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.

Community
  • 1
  • 1
nefas
  • 1,120
  • 7
  • 16

1 Answers1

1

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

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

Output:

"t1"
"t2"
peak
  • 105,803
  • 17
  • 152
  • 177