空手道:JsonPath 通配符不起作用或部分不起作用
Karate: JsonPath wildcards didn't work or partly didn't work
JSON 文件 jsonExample
:
{
"store": {
"book": [
{
"category": "fiction",
"author": "Evelyn Waugh",
"title": "Sword of Honour",
"something": 12.99
}
],
"bicycle": {
"color": "red",
"price": 19.95
}
},
"expensive": 10
}
我要更新 "something"
。当我使用:
1) * set jsonExample $.store.book[0].something = 13
- 正在运行
2) * set jsonExample $..book[0].something = 13
- 正在运行
3) * eval jsonExample.store.book[0].something = 13
- 正在运行
但是
1) * set jsonExample $..something = 13
- 不 工作
2) * eval jsonExample..something = 13
- 不 工作
我知道 set
不能使用通配符($[*].foo
或 $..foo
)。但是通配符可以与 eval 一起使用吗?如果是,如何?请根据上面的文件 jsonExample
举例。
我不明白你为什么这么关心这个。通配符不适用于 updating JSON。就是这么简单。
还有一件事,eval
仅适用于纯 JS。 Json-路径是 NOT 纯 JS。
也许这会解释得更清楚。
如果* set jsonExample $..book[0].something = 13
正常,请假设这是一个BUG。不要依赖它。它可能在这种情况下有效,因为代码尽可能具有弹性。但它可能不适用于其他情况或未来版本的空手道。
以下所有方法都有效:
* def jsonExample =
"""
{
"store": {
"book": [
{
"category": "fiction",
"author": "Evelyn Waugh",
"title": "Sword of Honour",
"something": 12.99
}
],
"bicycle": {
"color": "red",
"price": 19.95
}
},
"expensive": 10
}
"""
# all these will work
* set jsonExample $.store.book[0].something = 13
* match jsonExample.store.book[0].something == 13
* set jsonExample.store.book[0].something = 14
* match jsonExample.store.book[0].something == 14
* eval jsonExample.store.book[0].something = 15
* match jsonExample.store.book[0].something == 15
我真的希望这能说明问题!!
JSON 文件 jsonExample
:
{
"store": {
"book": [
{
"category": "fiction",
"author": "Evelyn Waugh",
"title": "Sword of Honour",
"something": 12.99
}
],
"bicycle": {
"color": "red",
"price": 19.95
}
},
"expensive": 10
}
我要更新 "something"
。当我使用:
1) * set jsonExample $.store.book[0].something = 13
- 正在运行
2) * set jsonExample $..book[0].something = 13
- 正在运行
3) * eval jsonExample.store.book[0].something = 13
- 正在运行
但是
1) * set jsonExample $..something = 13
- 不 工作
2) * eval jsonExample..something = 13
- 不 工作
我知道 set
不能使用通配符($[*].foo
或 $..foo
)。但是通配符可以与 eval 一起使用吗?如果是,如何?请根据上面的文件 jsonExample
举例。
我不明白你为什么这么关心这个。通配符不适用于 updating JSON。就是这么简单。
还有一件事,eval
仅适用于纯 JS。 Json-路径是 NOT 纯 JS。
也许这会解释得更清楚。
如果* set jsonExample $..book[0].something = 13
正常,请假设这是一个BUG。不要依赖它。它可能在这种情况下有效,因为代码尽可能具有弹性。但它可能不适用于其他情况或未来版本的空手道。
以下所有方法都有效:
* def jsonExample =
"""
{
"store": {
"book": [
{
"category": "fiction",
"author": "Evelyn Waugh",
"title": "Sword of Honour",
"something": 12.99
}
],
"bicycle": {
"color": "red",
"price": 19.95
}
},
"expensive": 10
}
"""
# all these will work
* set jsonExample $.store.book[0].something = 13
* match jsonExample.store.book[0].something == 13
* set jsonExample.store.book[0].something = 14
* match jsonExample.store.book[0].something == 14
* eval jsonExample.store.book[0].something = 15
* match jsonExample.store.book[0].something == 15
我真的希望这能说明问题!!