I am replicating of my problem with this JSON string
{
"store": {
"book": [
{
"category": "reference",
"author": "Nigel Rees",
"title": "Sayings of the Century",
"price":[ {
"amount": 8.95,
"money":{"amount":8900}
}],
"amount":9.9
},
{
"category": "fiction",
"author": "Evelyn Waugh",
"title": "Sword of Honour",
"price":{ "amount":12.99}
},
{
"category": "fiction",
"author": "Herman Melville",
"title": "Moby Dick",
"isbn": "0-553-21311-3",
"price": 8.99
},
{
"category": "fiction",
"author": "J. R. R. Tolkien",
"title": "The Lord of the Rings",
"isbn": "0-395-19395-8",
"price": 22.99
}
]
,
"bicycle": {
"color": "red",
"price": 19.95
}
},
"expensive": 10
}
I want value of amount which is in tag 'price' , not inside in tag 'money'
Now I have 3 scenario :-
1) $..book..price..amount
by this jpath , my response is
[
"$['store']['book'][0]['price'][0]['amount']",
"$['store']['book'][0]['price'][0]['money']['amount']",
"$['store']['book'][1]['price']['amount']"
]
which is wrong because it includes value of tag 'amount' which is grand child of price and child of 'money',
but I only wants value 'amount' which is direct child of price.
2) So, Now I am using '[*]' in place of '..'
$..book..price[*]amount
by this jpath, my response is,
[
"$['store']['book'][0]['price'][0]['amount']"
]
which is not includes below path
"$['store']['book'][1]['price']['amount']"
beacuse inside [1] index of book, object price is not an array, it is simple object ,so '[*]' only works in case of array type object.
so this will not producing right results as well.
3) So by using only one dot in place of [*]
$..book..price.amount
by this jpath my response is
[
"$['store']['book'][1]['price']['amount']"
]
which does not includes bellow path
[
"$['store']['book'][0]['price'][0]['amount']"
]
I want bellow jpath in my results.
[
"$['store']['book'][1]['price']['amount']"
"$['store']['book'][0]['price'][0]['amount']"
]