Reputation: 549
I have the below JSON
{
"RestResponse": {
"messages": [
"Total [36] records found."
],
"result": [
{
"id": 56,
"country": "IND",
"name": "Andhra Pradesh",
"abbr": "AP",
"area": "49506799SKM",
"largest_city": "Hyderabad Amaravati",
"capital": "Hyderabad Amaravati"
}
]
}
}
To access the name I am trying to give the JSONPath as
$RestResponse.result[*].name
also as
$RestResponse.result[:1].name
Both seems to be not working.
Upvotes: 1
Views: 135
Reputation: 323
JSONPath expressions can use the dot–notation or the bracket–notation for input pathes. Learn JsonPath
bracket–notation
$['RestResponse']['result'][0]['name']
dot–notation
$.RestResponse.result[0].name
You can try JsonPath Expression Tester here
Upvotes: 0
Reputation: 280
You need to change it to $.RestResponse.result[*].name
. The dot notation is important from the root element $, as in every other part of the jsonpath query.
Upvotes: 1