0

I'm trying to figure out how to print just the attributes->preferences section in the following JSON example using jq. What's throwing me is that this is an array that contains multiple entries that are identified by an id key value pair and I need the attributes->preferences section just from the array element with id 1 without knowing the exact order of the array entries ahead of time.

[
  {
    "id": 1,
    "attributes": {
      "preferences": {
        "key1": "value1",
        "key2": "value2",
        "key3": "value3",
        "key4": "value4",
        ...
      }
    },
    ...
  },
  {
    "id": 2,
    ...
  },
  {
    "id": 4,
    ...
  },
  ...
]

My desired output would be:

{
  "key1": "value1",
  "key2": "value2",
  "key3": "value3",
  "key4": "value4",
  ...
}
0

1 Answer 1

1
jq '.[] | select( .id == 1 ) | .attributes.preferences'

Demo on jqplay

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.