Get item from root array by a nested property using JMESPath

38 Views Asked by At

I've got this json:

[
  {
    "data": "interesting data",
    "definition":{
      "id":2216
    }
  },
  {
    "data": "irrelevant data",
    "definition":{
      "id":2217
    }
  }
]

I'm trying to get the full object, including the "interesting data" of the item with definition id 2216. In other words, I want something that looks like this result:

{
  "data": "interesting data",
  "definition":{
    "id":2216
  }
}

What query do i need?

I've spent an hour to figure it out using the documentation, google and other stack overflow posts, but I haven't found a solution yet.

1

There are 1 best solutions below

0
Janneman96 On

The answer is:

[?definition.id == `2216`]

That results to:

[
  {
    "data": "interesting data",
    "definition": {
      "id": 2216
    }
  }
]

Turns out you need the backtick (`) character around integers.