Search code examples
jsonjmeterjsonpath

JSONPath expression to get an object from an array based on condition


Given JSON structure

{
  "total_institutions": 2,
  "count_by_institution": [
    {
      "institution": {
        "id": "03629",
        "name": "institutiona03629"
      },
      "total_branches": 5
    },
    {
      "institution": {
        "id": "03659",
        "name": "institutiona03659"
      },
      "total_branches": 3
    }
  ]
}

I am new to JSon Path. I would need a JSONPath expression to get institution object that has name equal to institutiona03659. So, given the example above, the result should be

{
  "institution": {
    "id": "03629",
    "name": "institutiona03629"
  },
  "total_branches": 5
}

Solution

  • How about

    $..[?(@.institution.name == 'institutiona03659')]
    

    enter image description here

    More information: