2

I have an array of objects similar to the following:

[
  {
    "id": "one",
    "tags": {
      "my.key": "true"
    }
  },
  {
    "id": "two",
  }
]

How can I select all "id" values for each object containing a tag where "my.key" is "true"?

1 Answer 1

3

You can use a select with .tags["my.key"] == "true" and get only the id field :

jq '.[] | select(.tags["my.key"] == "true") | .id' data.json
Sign up to request clarification or add additional context in comments.

2 Comments

Thanks for the speedy response! I also got an alternative solution based on another answer: map(select(.tags["my.key"] == "true")) | .[] .id
which is pretty much the same thing. I had a typo in my "select" syntax which you helped me to find, thanks :)

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.