简体   繁体   English

如何使用 Json Extractor 从 Jmeter 中嵌套的 Json 中提取数据

[英]How to extract data from nested Json in Jmeter using Json Extractor

{"data": {"callOrders": [{ "promotionId": null, "Promotion": null, "Lines": [ { "id": 5105808, "quantity": 10, "skuId": 769, "callId": 494285, "skuBatchId": 733, "amountDetails": { "rate": 197.53, "grossAmount": 2232.089, "netAmount": 2232.089, "taxAmount": 256.789, "taxableAmount": 1975.3, "subTotal": 1975.3, "billDiscount": 0, "tradeDiscount": 0, "discountAmount": 0, "promotionDiscount": 0, "topUpDiscount": 0, "__typename": "AmountDetail" }, "rateDetails": { "rlp": 197.53, "rlpWithVat": 223.2089, "netPrice": 197.53, "netPriceWithVat": 223.2089, "__typename": "RateDetail" }, "SKU": { "id": 769, "title": "H&S 2in1 Active Protect 180 ml x 24 [82302894]", "__typename": "SKU" }, "SKUBatch": { "priceDetails": { "rlp": 197.53, "dlp": 186.35, "vatPercentage": 0.13, "mrpSrp": 250, "mrpStatus": true, "__typename": "SKUPrice" }, "batchDetails": { "batchNumber": "DEFAULT_BATCH", "__typename": "SKUBatch" }, "usageDate": { "manufacture": "0000-00-00", "expiry": "0000-00-00", "__typename": "SKUUsag {"data": {"callOrders": [{ "promotionId": null, "Promotion": null, "Lines": [ { "id": 5105808, "quantity": 10, "skuId": 769, "callId" ": 494285, "skuBatchId": 733, "amountDetails": { "rate": 197.53, "grossAmount": 2232.089, "netAmount": 2232.089, "taxAmount": 256.789, "taxable":191957Total" , "billDiscount": 0, "tradeDiscount": 0, "discountAmount": 0, "promotionDiscount": 0, "topUpDiscount": 0, "__typename": "AmountDetail" }, "rateDetails": { "rlp": 197.53 , "rlpWithVat": 223.2089, "netPrice": 197.53, "netPriceWithVat": 223.2089, "__typename": "RateDetail" }, "SKU": { "id": 769, "title": "H&S 2in1 ml Active Protect 18 x 24 [82302894]", "__typename": "SKU" }, "SKUBatch": { "priceDetails": { "rlp": 197.53, "dlp": 186.35, "vatPercentage": 0.13, "mrpSrp": 250, "mrpStatus": true, "__typename": "SKUPrice" }, "batchDetails": { "batchNumber": "DEFAULT_BATCH", "__typename": "SKUBatch" }, "usageDate": { "manufacture": "0000-00 -00", "expiry": "0000-00-00", "__typename": "SKUUsag e" }, "updatedAt": "2019-11-05", "active": true, "__typename": "SKUBatchRate" }, "Promotion": { "id": null, "title": null, "type": null, "scope": null, "criteria": null, "__typename": "Promotion" }, "promotionId": null, "distributorId": 16, "__typename": "Line", "inStock": "INSTOCK", "freeSku": false, "focusedSku": false }, { "id": 5105809, "quantity": 50, "skuId": 95, "callId": 494285, "skuBatchId": 111, "amountDetails": { "rate": 56.89, "grossAmount": 3214.2852, "netAmount": 3214.285, "taxAmount": 369.785, "taxableAmount": 2844.5, "subTotal": 2844.5, "billDiscount": 0, "tradeDiscount": 0, "discountAmount": 0, "promotionDiscount": 0, "topUpDiscount": 0, "__typename": "AmountDetail" }, "rateDetails": { "rlp": 56.89, "rlpWithVat": 64.2857, "netPrice": 56.89, "netPriceWithVat": 64.2857, "__typename": "RateDetail" }, "SKU": { "id": 95, "title": "Whisper Choice 6s x 96 [82252488]", "__typename": "SKU" }, "SKUBatch": { "priceDetails": { "rlp": 56.89, "dlp": 53.67, "vatPercentage": 0.13, "mr e" }, "updatedAt": "2019-11-05", "active": true, "__typename": "SKUBatchRate" }, "Promotion": { "id": null, "title": null, "type ": null, "scope": null, "criteria": null, "__typename": "Promotion" }, "promotionId": null, "distributorId": 16, "__typename": "Line", "inStock": " INSTOCK", "freeSku": false, "focusedSku": false }, { "id": 5105809, "quantity": 50, "skuId": 95, "callId": 494285, "skuBatchId": 111, "amountDetails" : { "rate": 56.89, "grossAmount": 3214.2852, "netAmount": 3214.285, "taxAmount": 369.785, "taxableAmount": 2844.5, "subTotal": 2844.5, "bill, Discount:0" "discountAmount": 0, "promotionDiscount": 0, "topUpDiscount": 0, "__typename": "AmountDetail" }, "rateDetails": { "rlp": 56.89, "rlpWithVat": 64.2857, "netPrice": 56.89, "netPriceWithVat": 64.2857, "__typename": "RateDetail" }, "SKU": { "id": 95, "title": "Whisper Choice 6s x 96 [82252488]", "__typename": "SKU" }, "SKUBatch": { "priceDetails": { "rlp": 56.89, "dlp": 53.67, "vatPercentage": 0.13, "mr pSrp": 72, "mrpStatus": true, "__typename": "SKUPrice" }, "batchDetails": { "batchNumber": "DEFAULT_BATCH", "__typename": "SKUBatch" }, "usageDate": { "manufacture": "0000-00-00", "expiry": "0000-00-00", "__typename": "SKUUsage" }, "updatedAt": "2016-08-15", "active": true, "__typename": "SKUBatchRate" }, "Promotion": { "id": null, "title": null, "type": null, "scope": null, "criteria": null, "__typename": "Promotion" }, "promotionId": null, "distributorId": 16, "__typename": "Line", "inStock": "INSTOCK", "freeSku": false, "focusedSku": false }, { "id": 5105810, "quantity": 10, "skuId": 82, "callId": 494285, "skuBatchId": 551, "amountDetails": { "rate": 281.88, "grossAmount": 3185.244, "netAmount": 3185.244, "taxAmount": 366.444, "taxableAmount": 2818.8, "subTotal": 2818.8, "billDiscount": 0, "tradeDiscount": 0, "discountAmount": 0, "promotionDiscount": 0, "topUpDiscount": 0, "__typename": "AmountDetail" }, "rateDetails": { "rlp": 281.88, "rlpWithVat": 318.5244, "netPrice": 281.88, "ne pSrp": 72, "mrpStatus": true, "__typename": "SKUPrice" }, "batchDetails": { "batchNumber": "DEFAULT_BATCH", "__typename": "SKUBatch" }, "usageDate": { "manufacture" : "0000-00-00", "expiry": "0000-00-00", "__typename": "SKUUsage" }, "updatedAt": "2016-08-15", "active": true, "__typename ": "SKUBatchRate" }, "Promotion": { "id": null, "title": null, "type": null, "scope": null, "criteria": null, "__typename": "Promotion" } , "promotionId": null, "distributorId": 16, "__typename": "Line", "inStock": "INSTOCK", "freeSku": false, "focusedSku": false }, { "id": 5105810, "数量”:10,“skuId”:82,“callId”:494285,“skuBatchId”:551,“amountDetails”:{“rate”:281.88,“grossAmount”:3185.244,“netAmount”:3185.244,“taxAmount”: 366.444, "taxableAmount": 2818.8, "subTotal": 2818.8, "billDiscount": 0, "tradeDiscount": 0, "discountAmount": 0, "promotionDiscount": 0, "topUpDiscount": 0, "__typename": "AmountDetail " }, "rateDetails": { "rlp": 281.88, "rlpWithVat": 318.5244, "netPrice": 281.88, "ne tPriceWithVat": 318.5244, "__typename": "RateDetail" }, "SKU": { "id": 82, "title": "Ariel Oxyblu 1 kg x 24 [82250306]", "__typename": "SKU" }, "SKUBatch": { "priceDetails": { "rlp": 281.88, "dlp": 268.45, "vatPercentage": 0.13, "mrpSrp": 344, "mrpStatus": true, "__typename": "SKUPrice" }, "batchDetails": { "batchNumber": "DEFAULT_BATCH", "__typename": "SKUBatch" }, "usageDate": { "manufacture": "0000-00-00", "expiry": "0000-00-00", "__typename": "SKUUsage" }, "updatedAt": "2018-01-31", "active": true, "__typename": "SKUBatchRate" }, "Promotion": { "id": null, "title": null, "type": null, "scope": null, "criteria": null, "__typename": "Promotion" }, "promotionId": null, "distributorId": 16, "__typename": "Line", "inStock": "INSTOCK", "freeSku": false, "focusedSku": false } ], "__typename": "PromotionOrder" }]}} tPriceWithVat": 318.5244, "__typename": "RateDetail" }, "SKU": { "id": 82, "title": "Ariel Oxyblu 1 kg x 24 [82250306]", "__typename": "SKU" }, "SKUBatch": { "priceDetails": { "rlp": 281.88, "dlp": 268.45, "vatPercentage": 0.13, "mrpSrp": 344, "mrpStatus": true, "__typename": "SKUPrice" }, " batchDetails": { "batchNumber": "DEFAULT_BATCH", "__typename": "SKUBatch" }, "usageDate": { "manufacture": "0000-00-00", "expiry": "0000-00-00", "__typename": "SKUUsage" }, "updatedAt": "2018-01-31", "active": true, "__typename": "SKUBatchRate" }, "Promotion": { "id": null, "title" : null, "type": null, "scope": null, "criteria": null, "__typename": "Promotion" }, "promotionId": null, "distributorId": 16, "__typename": "Line", "inStock": "INSTOCK", "freeSku": false, "focusedSku": false } ], "__typename": "PromotionOrder" }]}}

Using $..Lines..id I am getting this [ 5105808, 769, null, 5105809, 95, null, 5105810, 82, null ]使用 $..Lines..id 我得到这个 [ 5105808, 769, null, 5105809, 95, null, 5105810, 82, null ]

But I want to get value [ 5105808, 5105809, 5105810] only.但我只想获得价值 [ 5105808, 5105809, 5105810] 。 What should be the way to achieve it?实现它的方法应该是什么?

This is a possible solution:这是一个可能的解决方案:

$..[?(@.skuId)].id $..[?(@.skuId)].id

This gets elements that have the skuId attribute and extracts the id attribute.这将获取具有 skuId 属性的元素并提取 id 属性。

You're using .. which is a deep scan operator which means that you're looking for all id attribute values no matter where they're located in the JSON.您正在使用..这是一个深度扫描运算符,这意味着您正在查找所有id属性值,无论它们位于 JSON 中的哪个位置。

If you want to get only id of the attributes which are direct children of the Lines object - you need to amend your query to look like: $..Lines[*].id如果您只想获取作为Lines对象的直接子级的属性的id - 您需要将查询修改为: $..Lines[*].id

Demo:演示:

在此处输入图片说明

More information: JMeter's JSON Path Extractor Plugin - Advanced Usage Scenarios更多信息: JMeter 的 JSON 路径提取器插件 - 高级使用场景

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

相关问题 如何在 jmeter 中使用 JSON Extractor 从数组中提取值? - How to extract values out of a array using JSON Extractor in jmeter? 如何在 Jmeter 中不使用 foreach controller 从数组中提取值(通过 JSON 提取器获得) - How to extract a value from an array (obtained through JSON extractor) without foreach controller in Jmeter 如何从嵌套的json数组中提取数据? - How to extract data from nested json array? JMeter JSON 提取器使用 -1 值 foreach controller 与不一致的数组 - JMeter JSON Extractor using -1 value for foreach controller with inconsistent array Rails 如何从嵌套的 JSON 数据中提取数据 - Rails how to extract data from nested JSON data Jackson JSON-从嵌套数组中提取数据 - Jackson JSON - Extract data from nested array 从深层嵌套中提取数据 JSON - Extract data from deeply-nested JSON 如何使用AWS Athena-Presto从NESTED JSON中的特定字段提取数据? - How to extract data from specific fields in a NESTED JSON using AWS Athena - Presto? 如何使用它们的键从嵌套的 JSON 数据数组中提取最内层的值? - How can I extract innermost value from an array of nested JSON data using their keys? 如何使用Python解析/提取嵌套的JSON数据? - How to parse/extract nested JSON data with Python?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM