【问题标题】:Karate not supporting JSON Path [duplicate]空手道不支持 JSON 路径 [重复]
【发布时间】:2019-03-26 14:48:24
【问题描述】:

我有一个 JSON 路径,比如 $[advertiserId],它的计算结果为

[
  "001E000000yBFskIAG"
]

使用工具https://jsonpath.com/? .

但是,等效的空手道语法不起作用:

并匹配 response[*].advertiserId == '001E000000yBFskIAG'

它无法识别这条路径。

如果我有 JSON:

{
"advertiserId":"someID"
}

然后

并匹配 response[*].advertiserId == 'someID'

应该可以。空手道应该能够支持基本的 JSON 匹配。

【问题讨论】:

    标签: karate


    【解决方案1】:

    空手道更严格 - 如果有 JsonPath “通配符”,例如*.. 结果将始终是一个数组。也许 jsonpath.com 将单个元素数组转换为方便的值 - 但我们永远不会这样做。

    以下工作:

    * def response = [{ advertiserId: '001E000000yBFskIAG' }]
    * match response[*].advertiserId == ['001E000000yBFskIAG']
    

    【讨论】:

    • 感谢您的回复,这很有帮助。我仍然认为这对空手道来说是一个可怕的限制,但我想任何解决方法都比没有解决方法好。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-02-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-11-25
    • 1970-01-01
    相关资源
    最近更新 更多