【问题标题】:How to return single value from list after filter using JSON Path extractor?使用 JSON 路径提取器过滤后如何从列表中返回单个值?
【发布时间】:2021-05-07 10:53:13
【问题描述】:

使用下面的示例测试 url 作为参考,我只想从结果中返回一个值。

http://jsonpath.herokuapp.com/?path=$..book[?(@.price%20%3C=%20$[%27expensive%27])]

通过在最后应用[:1] 尝试它不起作用

【问题讨论】:

    标签: jmeter jsonpath


    【解决方案1】:

    最简单的选择就是使用JSON Extractor 的“匹配号”字段:

    • -1 - 你会得到两个匹配项

       inexpensive_1={"category":"reference","title":"Sayings of the Century","author":"Nigel Rees","price":8.95}
       inexpensive_2={"category":"fiction","title":"Moby Dick","author":"Herman Melville","price":8.99,"isbn":"0-553-21311-3"}
       inexpensive_matchNr=2
      
    • 1 - 你会得到第一场比赛

       inexpensive={"category":"reference","title":"Sayings of the Century","author":"Nigel Rees","price":8.95}
      
    • 2 - 你将获得第二场比赛:

       inexpensive={"category":"fiction","title":"Moby Dick","author":"Herman Melville","price":8.99,"isbn":"0-553-21311-3"}
      
    • 0 - 你会得到随机匹配

    或者你也可以选择JSON JMESPath Extractor,它有pipe expressions

    store.book[?price<`10`] | [0]
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-12-05
      • 2021-12-03
      • 1970-01-01
      • 2015-01-29
      • 1970-01-01
      相关资源
      最近更新 更多