-1

Example JSON file:

{
  "propertyName1": {
    "name": "Anthony",
    "age": 10
  },
  "propertyName2": {
    "name": "Eric",
    "age": 12
  }
}

I need to find the name which age is 10 for example

("properyName1.find{it.age == '10'}.name"). is not working, the propertyName1 is not an array

I need this because in this example I know the age, and with age, I want to find the name. How can I find the needed data?

Mark Rotteveel
  • 100,966
  • 191
  • 140
  • 197
Norayr Sargsyan
  • 1,737
  • 1
  • 12
  • 26

1 Answers1

1

JsonPath has quite different syntax, so I believe this one should be working for you:

String ageValue = response.path("propertyName1.age").toString();

// path() method returns Object by default, but as you see, you can cast to the type what you need.

Villa_7
  • 508
  • 4
  • 14