简体   繁体   English

如何使用 JSON 提取器提取 JSON 响应中的嵌套元素

[英]How to extract nested elements in JSON response using JSON extractor

I need to extract an element based on a condition inside a nested JSON response.我需要根据嵌套 JSON 响应中的条件提取元素。

{
   "cabin":"eco",
   "seatNumber":"15A",
   "travelers":[
      {
         "id":"7789",
         "seatCharacteristicsCodes":[
            "CH",
            "W"
         ],
         "seatAvailabilityStatus":"available",
         "prices":[
            {
               "base":40,
               "total":40,
               "currencyCode":"AED",
               "totalTaxes":0
            }
         ]
      }
   ],
   "coordinates":{
      "x":1,
      "y":0
   }
}

I need to check the "seatAvailabilityStatus" as "available" or not (which is inside "travelers"), if it is available, I need to get the "seatNumber" and proceed with the flow.我需要检查“seatAvailabilityStatus”是否为“可用”(位于“旅行者”内部),如果可用,我需要获取“seatNumber”并继续流程。

I have seen some example and tried like the below, but I am able to capture only the values which are associated to "travelers" like "id" or "prices":我看过一些示例并尝试如下,但我只能捕获与“旅行者”相关的值,如“id”或“prices”:

$.travelers[?(@.seatAvailabilityStatus=="available")].id

But in my case, if the seatAvailabilityStatus is available I need to get the "seatNumber".但就我而言,如果座位可用状态可用,我需要获取“座位号”。 Can anyone help?任何人都可以帮忙吗?

Screen shot of the JSON I included我包括的 JSON 的屏幕截图

You could try this way:你可以这样尝试:

$..[?(@.travelers[?(@.seatAvailabilityStatus =='available')] empty false)].seatNumber

You need to get 1 level up because JsonPath doesn't know anything about parents of the matched attribute您需要升级 1 级,因为 JsonPath对匹配属性的父级一无所知

Suggested query:建议查询:

$..[?(@.travelers[?(@.seatAvailabilityStatus =='available')])].seatNumber

Demo:演示:

在此处输入图像描述

More information: How to Use the JSON Extractor For Testing更多信息:如何使用 JSON 提取器进行测试

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在 JMeter 中使用 JSON 提取器提取 JSON 响应中的嵌套元素 - How to extract nested elements in JSON response using JSON extractor in JMeter 如何使用 Json Extractor 从 Jmeter 中嵌套的 Json 中提取数据 - How to extract data from nested Json in Jmeter using Json Extractor 使用JSON提取器从响应中提取值 - Using JSON extractor to extract values from the response 如何使用正则表达式提取器在jmeter中提取json响应数据? - how to extract json response data in jmeter using regular expression extractor? 如何使用 Jmeter 中的 JSON JMESpasth Extractor 从 JSON 响应中提取所有 id? - How to extract all id's from a JSON response using JSON JMESPasth Extractor in Jmeter? 如何使用json路径提取器提取json Responce? - How to extract json Responce using json path extractor? 如何使用正则表达式提取器在jmeter响应数据中提取JSON值 - How the JSON value extract process in jmeter response data using regular expression extractor 使用 jMeter 中的 JSON Extractor 从 JSON 中提取嵌套的 JSON 内容 - Extract nested JSON content from JSON with use of JSON Extractor in jMeter 如何在Jmeter中使用JSON提取器提取列表中的特定值 - How to Extract specific value in list using JSON extractor in Jmeter 如何使用正则表达式提取器提取jmeter中的Json值? - How to extract the Json values in jmeter using regular expression extractor?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM