JSON file jsonExample
:
{
"store": {
"book": [
{
"category": "fiction",
"author": "Evelyn Waugh",
"title": "Sword of Honour",
"something": 12.99
}
],
"bicycle": {
"color": "red",
"price": 19.95
}
},
"expensive": 10
}
I want update "something"
. When I use:
1) * set jsonExample $.store.book[0].something = 13
- it is working
2) * set jsonExample $..book[0].something = 13
- it is working
3) * eval jsonExample.store.book[0].something = 13
- it is working
BUT
1) * set jsonExample $..something = 13
- it is NOT working
2) * eval jsonExample..something = 13
- it is NOT working
I understand that set
is not working with wildcards ($[*].foo
or $..foo
). But are wildcards working with eval? If yes, how? Please example based on file jsonExample
above.
I don't understand why you are so concerned with this. Wildcards will not work for updating JSON. It is that simple.
And one more thing,
eval
will work with pure JS only. Json-Path is NOT pure JS.Maybe this will explain it more clearly.
If
* set jsonExample $..book[0].something = 13
is working please assume that it is a BUG. Do not rely on it. It may work in this case because the code is resilient as far as possible. But it may not work in other cases or in future versions of Karate.All the below will work:
I really hope this makes it clear !!