Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Json filter data on the sibling node

Tags:

json

jsonpath

I am new with JSONPath and any help is appreciated. I am trying to filter data based on its sibling value.

My JSON sample:

[

  {
  "id": "10300",
  "name": "NAME1"
  },
  {
  "id": "10500",
  "name": "NAME2"
  }
 ]

And I would like to query id by the name. I tried something like this, but without luck:

$..id[?(@name=='NAME1')]

I am sure I missed something trivial.

like image 979
Gico Avatar asked Dec 10 '22 11:12

Gico


1 Answers

I found the solution by myself after all.

$..[?(@.name == 'NAME1')].id
like image 50
Gico Avatar answered Dec 31 '22 15:12

Gico