需要从JSON检索值的组合

需要从JSON检索值的组合,json,xpath,Json,Xpath,从上面的JSON中,我需要检索适用于logicalContainerNbr 1的UPC列表。请在XPath 3.1中帮助我解决这个问题,它类似于 { "apiVersion": "2.0", "id": "4c40ded9-90cd-434a-992f-0d7217579f42", "data": { "localTimeZoneId": "America/Chicago", "workId": "193224", "workType": "pick",

从上面的JSON中,我需要检索适用于logicalContainerNbr 1的UPC列表。请在XPath 3.1中帮助我解决这个问题,它类似于

{
  "apiVersion": "2.0",
  "id": "4c40ded9-90cd-434a-992f-0d7217579f42",
  "data": {
    "localTimeZoneId": "America/Chicago",
    "workId": "193224",
    "workType": "pick",
    "custOrds": [
      {
        "customer": {
          "firstName": "automationtest",
          "lastName": "test",
          "type": null,
          "address": null,
          "phone": {
            "primary": "1234567890",
            "secondary": "281 2996076"
          }
        },
        "order": {
          "custOrdNbr": "1121013511690",
          "fulfillOrdNbr": 1729665,
          "pickDueTime": "2019-11-20T20:35:00.0000",
          "expOrdPickupTime": "2019-11-20T21:05:00.0000",
          "localPickDueTime": "2019-11-20T14:35:00.0000",
          "localExpOrdPickupTime": "2019-11-20T15:05:00.0000",
          "fulfillType": null,
          "fulfillTypeDesc": null,
          "fulfillTypeName": "GRP",
          "prepaid": true,
          "ordInst": null,
          "ordSeqNbr": "1690",
          "loadGroupNbr": "46",
          "carrierBagAllowed": false,
          "captureCarrierBagCount": false,
          "divisionNbr": "1",
          "containers": []
        }
      },
      {
        "customer": {
          "firstName": "first7427183256340",
          "lastName": "last7427183256340",
          "type": null,
          "address": "21702 W 62nd Street, Shawnee, KS KS",
          "phone": {
            "primary": "010009819",
            "secondary": "0100098179"
          }
        },
        "order": {
          "custOrdNbr": "7427183256340",
          "fulfillOrdNbr": 1729603,
          "pickDueTime": "2019-11-20T21:30:00.0000",
          "expOrdPickupTime": "2019-11-20T22:00:00.0000",
          "localPickDueTime": "2019-11-20T15:30:00.0000",
          "localExpOrdPickupTime": "2019-11-20T16:00:00.0000",
          "fulfillType": null,
          "fulfillTypeDesc": null,
          "fulfillTypeName": "GRP",
          "prepaid": true,
          "ordInst": null,
          "ordSeqNbr": "450",
          "loadGroupNbr": "29",
          "carrierBagAllowed": false,
          "captureCarrierBagCount": false,
          "divisionNbr": "1",
          "containers": []
        }
      },
      {
        "customer": {
          "firstName": "automationtest",
          "lastName": "test",
          "type": null,
          "address": null,
          "phone": {
            "primary": "1234567890",
            "secondary": "281 2996076"
          }
        },
        "order": {
          "custOrdNbr": "11210147441911",
          "fulfillOrdNbr": 1729677,
          "pickDueTime": "2019-11-20T20:47:00.0000",
          "expOrdPickupTime": "2019-11-20T21:17:00.0000",
          "localPickDueTime": "2019-11-20T14:47:00.0000",
          "localExpOrdPickupTime": "2019-11-20T15:17:00.0000",
          "fulfillType": null,
          "fulfillTypeDesc": null,
          "fulfillTypeName": "GRP",
          "prepaid": true,
          "ordInst": null,
          "ordSeqNbr": "1911",
          "loadGroupNbr": "46",
          "carrierBagAllowed": false,
          "captureCarrierBagCount": false,
          "divisionNbr": "1",
          "containers": []
        }
      }
    ],
    "marketConf": {
      "overrideAllowed": true,
      "partialPickAllowed": true,
      "rbemEnabled": false,
      "validSubFactor": 30
    },
    "pickWorkDetail": [
      {
        "pickDetail": {
          "toBePickedQty": 0,
          "toBePickedWgt": 3.5,
          "prevPickedWgt": 0
        },
        "workDetail": {
          "fulfillOrdNbr": 1729677,
          "upc": "4689",
          "ordLine": 1,
          "desc": "MILK",
          "dotcomDesc": "Great Value Premium Assorted Clear Cutlery, 96 count",
          "fineLine": 205,
          "productType": null,
          "facilityPrice": 1.78,
          "color": "",
          "size": "",
          "onHandQty": 508,
          "custNotes": null,
          "pickingInst": null,
          "uom": "LB",
          "wgtUom": "LB",
          "pickByType": "WEIGHTED",
          "upperThresholdLimit": 4.9,
          "lowerThresholdLimit": 0.7,
          "acceptUpcs": [
            {
              "upc": "4689",
              "subCd": 5100,
              "activations": []
            }
          ],
          "subAllowed": false,
          "suggestedSubAllowed": false,
          "deptCategory": 56,
          "deptDesc": null,
          "prefQtyOrWgt": 0,
          "tempBandCode": 1,
          "imageUrl": "https://i5.test.com/asr/69340e2a-3758-4c28-95ca-11240de72cd6_1.91c46883f2bb00cfd7a331a406529e5a.jpeg",
          "minFreshnessDate": null,
          "idealFreshnessDate": null,
          "itemNbr": 553425776,
          "containers": [
            {
              "logicalContainerNbr": 2,
              "toBePickedQty": 0,
              "toBePickedWgt": 3.5
            }
          ]
        }
      },
      {
        "pickDetail": {
          "toBePickedQty": 1,
          "toBePickedWgt": 0,
          "prevPickedWgt": 0
        },
        "workDetail": {
          "fulfillOrdNbr": 1729603,
          "upc": "4011",
          "ordLine": 1,
          "desc": "BANANA PREM PER LB",
          "dotcomDesc": "AP DK MIRACLE CREME",
          "fineLine": 5501,
          "productType": null,
          "facilityPrice": 0.18,
          "color": "Yellow",
          "size": "",
          "onHandQty": 3837,
          "custNotes": null,
          "pickingInst": null,
          "uom": "EACH",
          "wgtUom": null,
          "pickByType": "EACH",
          "upperThresholdLimit": 0,
          "lowerThresholdLimit": 0,
          "acceptUpcs": [
            {
              "upc": "4011",
              "subCd": 5100,
              "activations": []
            }
          ],
          "subAllowed": true,
          "suggestedSubAllowed": true,
          "deptCategory": 94,
          "deptDesc": "VEGETABLES",
          "prefQtyOrWgt": 0,
          "tempBandCode": 1,
          "imageUrl": "https://i5-qa.test.com/asr/203a9f6a-e83e-41f8-abfb-cb2e7bd86f4f_1.28ae5142550021e1c03216b99c07be2e.jpeg?odnHeight=180&odnWidth=180&odnBg=ffffff",
          "minFreshnessDate": null,
          "idealFreshnessDate": null,
          "itemNbr": 553695402,
          "containers": [
            {
              "logicalContainerNbr": 3,
              "toBePickedQty": 1,
              "toBePickedWgt": 0
            }
          ]
        }
      },
      {
        "pickDetail": {
          "toBePickedQty": 1,
          "toBePickedWgt": 0,
          "prevPickedWgt": 0
        },
        "workDetail": {
          "fulfillOrdNbr": 1729665,
          "upc": "4139002404",
          "ordLine": 4,
          "desc": "MILK",
          "dotcomDesc": "Great Value Premium Assorted Clear Cutlery, 96 count",
          "fineLine": 205,
          "productType": null,
          "facilityPrice": 3.98,
          "color": "",
          "size": "",
          "onHandQty": 0,
          "custNotes": null,
          "pickingInst": null,
          "uom": "EACH",
          "wgtUom": null,
          "pickByType": "EACH",
          "upperThresholdLimit": 0,
          "lowerThresholdLimit": 0,
          "acceptUpcs": [
            {
              "upc": "4139002404",
              "subCd": 5100,
              "activations": []
            }
          ],
          "subAllowed": false,
          "suggestedSubAllowed": false,
          "deptCategory": 68,
          "deptDesc": null,
          "prefQtyOrWgt": 0,
          "tempBandCode": 1,
          "imageUrl": "https://i5.test.com/asr/69340e2a-3758-4c28-95ca-11240de72cd6_1.91c46883f2bb00cfd7a331a406529e5a.jpeg",
          "minFreshnessDate": null,
          "idealFreshnessDate": null,
          "itemNbr": 2384523,
          "containers": [
            {
              "logicalContainerNbr": 1,
              "toBePickedQty": 1,
              "toBePickedWgt": 0
            }
          ]
        }
      },
      {
        "pickDetail": {
          "toBePickedQty": 3,
          "toBePickedWgt": 0,
          "prevPickedWgt": 0
        },
        "workDetail": {
          "fulfillOrdNbr": 1729677,
          "upc": "4688",
          "ordLine": 2,
          "desc": "BELL RED HM",
          "dotcomDesc": "Great Value Premium Assorted Clear Cutlery, 96 count",
          "fineLine": 8103,
          "productType": null,
          "facilityPrice": 1.72,
          "color": "",
          "size": "",
          "onHandQty": 265,
          "custNotes": null,
          "pickingInst": null,
          "uom": "EACH",
          "wgtUom": null,
          "pickByType": "EACH",
          "upperThresholdLimit": 0,
          "lowerThresholdLimit": 0,
          "acceptUpcs": [
            {
              "upc": "4688",
              "subCd": 5100,
              "activations": []
            }
          ],
          "subAllowed": false,
          "suggestedSubAllowed": false,
          "deptCategory": 94,
          "deptDesc": null,
          "prefQtyOrWgt": 0,
          "tempBandCode": 1,
          "imageUrl": "https://i5.test.com/asr/69340e2a-3758-4c28-95ca-11240de72cd6_1.91c46883f2bb00cfd7a331a406529e5a.jpeg",
          "minFreshnessDate": null,
          "idealFreshnessDate": null,
          "itemNbr": 553425802,
          "containers": [
            {
              "logicalContainerNbr": 2,
              "toBePickedQty": 3,
              "toBePickedWgt": 0
            }
          ]
        }
      },
      {
        "pickDetail": {
          "toBePickedQty": 2,
          "toBePickedWgt": 0,
          "prevPickedWgt": 0
        },
        "workDetail": {
          "fulfillOrdNbr": 1729665,
          "upc": "4000044327",
          "ordLine": 5,
          "desc": "SNKRS FULL 6PK",
          "dotcomDesc": "Great Value Premium Assorted Clear Cutlery, 96 count",
          "fineLine": 75,
          "productType": null,
          "facilityPrice": 3.98,
          "color": "",
          "size": "",
          "onHandQty": 0,
          "custNotes": null,
          "pickingInst": null,
          "uom": "EACH",
          "wgtUom": null,
          "pickByType": "EACH",
          "upperThresholdLimit": 0,
          "lowerThresholdLimit": 0,
          "acceptUpcs": [
            {
              "upc": "4000044327",
              "subCd": 5100,
              "activations": []
            }
          ],
          "subAllowed": true,
          "suggestedSubAllowed": true,
          "deptCategory": 1,
          "deptDesc": null,
          "prefQtyOrWgt": 0,
          "tempBandCode": 1,
          "imageUrl": "https://i5-qa.test.com/asr/b26369ba-48b7-4a0e-88cd-9466c3751952.jpg?odnHeight=180&odnWidth=180&odnBg=ffffff",
          "minFreshnessDate": null,
          "idealFreshnessDate": null,
          "itemNbr": 550992538,
          "containers": [
            {
              "logicalContainerNbr": 1,
              "toBePickedQty": 2,
              "toBePickedWgt": 0
            }
          ]
        }
      },
      {
        "pickDetail": {
          "toBePickedQty": 0,
          "toBePickedWgt": 3.5,
          "prevPickedWgt": 0
        },
        "workDetail": {
          "fulfillOrdNbr": 1729665,
          "upc": "4689",
          "ordLine": 1,
          "desc": "MILK",
          "dotcomDesc": "Great Value Premium Assorted Clear Cutlery, 96 count",
          "fineLine": 205,
          "productType": null,
          "facilityPrice": 1.78,
          "color": "",
          "size": "",
          "onHandQty": 508,
          "custNotes": null,
          "pickingInst": null,
          "uom": "LB",
          "wgtUom": "LB",
          "pickByType": "WEIGHTED",
          "upperThresholdLimit": 4.9,
          "lowerThresholdLimit": 0.7,
          "acceptUpcs": [
            {
              "upc": "4689",
              "subCd": 5100,
              "activations": []
            }
          ],
          "subAllowed": false,
          "suggestedSubAllowed": false,
          "deptCategory": 56,
          "deptDesc": null,
          "prefQtyOrWgt": 0,
          "tempBandCode": 1,
          "imageUrl": "https://i5.test.com/asr/69340e2a-3758-4c28-95ca-11240de72cd6_1.91c46883f2bb00cfd7a331a406529e5a.jpeg",
          "minFreshnessDate": null,
          "idealFreshnessDate": null,
          "itemNbr": 553425776,
          "containers": [
            {
              "logicalContainerNbr": 1,
              "toBePickedQty": 0,
              "toBePickedWgt": 3.5
            }
          ]
        }
      },
      {
        "pickDetail": {
          "toBePickedQty": 3,
          "toBePickedWgt": 0,
          "prevPickedWgt": 0
        },
        "workDetail": {
          "fulfillOrdNbr": 1729665,
          "upc": "4688",
          "ordLine": 2,
          "desc": "BELL RED HM",
          "dotcomDesc": "Great Value Premium Assorted Clear Cutlery, 96 count",
          "fineLine": 8103,
          "productType": null,
          "facilityPrice": 1.72,
          "color": "",
          "size": "",
          "onHandQty": 265,
          "custNotes": null,
          "pickingInst": null,
          "uom": "EACH",
          "wgtUom": null,
          "pickByType": "EACH",
          "upperThresholdLimit": 0,
          "lowerThresholdLimit": 0,
          "acceptUpcs": [
            {
              "upc": "4688",
              "subCd": 5100,
              "activations": []
            }
          ],
          "subAllowed": false,
          "suggestedSubAllowed": false,
          "deptCategory": 94,
          "deptDesc": null,
          "prefQtyOrWgt": 0,
          "tempBandCode": 1,
          "imageUrl": "https://i5.test.com/asr/69340e2a-3758-4c28-95ca-11240de72cd6_1.91c46883f2bb00cfd7a331a406529e5a.jpeg",
          "minFreshnessDate": null,
          "idealFreshnessDate": null,
          "itemNbr": 553425802,
          "containers": [
            {
              "logicalContainerNbr": 1,
              "toBePickedQty": 3,
              "toBePickedWgt": 0
            }
          ]
        }
      }
    ],
    "pickContainers": [
      {
        "logicalContainerNbr": 1,
        "physicalContainerNbr": "D46496"
      },
      {
        "logicalContainerNbr": 2,
        "physicalContainerNbr": "D46494"
      },
      {
        "logicalContainerNbr": 3,
        "physicalContainerNbr": "D46495"
      }
    ],
    "pickRoute": [
      {
        "fulfillOrdNbr": 1729665,
        "ordLine": 1,
        "upc": "4689",
        "location": "A1-3-0004",
        "locId": 1,
        "locType": "SALESFLOOR",
        "availableLocsToPick": 1,
        "sequence": 4,
        "suggSubPendingPicks": false,
        "manualSubPendingPicks": false,
        "otherLocs": []
      },
      {
        "fulfillOrdNbr": 1729665,
        "ordLine": 2,
        "upc": "4688",
        "location": "A1-3-0003",
        "locId": 1,
        "locType": "SALESFLOOR",
        "availableLocsToPick": 1,
        "sequence": 4,
        "suggSubPendingPicks": false,
        "manualSubPendingPicks": false,
        "otherLocs": []
      },
      {
        "fulfillOrdNbr": 1729677,
        "ordLine": 1,
        "upc": "4689",
        "location": "A1-3-0004",
        "locId": 1,
        "locType": "SALESFLOOR",
        "availableLocsToPick": 1,
        "sequence": 4,
        "suggSubPendingPicks": false,
        "manualSubPendingPicks": false,
        "otherLocs": []
      },
      {
        "fulfillOrdNbr": 1729677,
        "ordLine": 2,
        "upc": "4688",
        "location": "A1-3-0003",
        "locId": 1,
        "locType": "SALESFLOOR",
        "availableLocsToPick": 1,
        "sequence": 4,
        "suggSubPendingPicks": false,
        "manualSubPendingPicks": false,
        "otherLocs": []
      },
      {
        "fulfillOrdNbr": 1729665,
        "ordLine": 4,
        "upc": "4139002404",
        "location": "A9-12-0037",
        "locId": 1,
        "locType": "SALESFLOOR",
        "availableLocsToPick": 1,
        "sequence": 9,
        "suggSubPendingPicks": false,
        "manualSubPendingPicks": false,
        "otherLocs": []
      },
      {
        "fulfillOrdNbr": 1729665,
        "ordLine": 5,
        "upc": "4000044327",
        "location": "A20-5-0053",
        "locId": 1,
        "locType": "SALESFLOOR",
        "availableLocsToPick": 1,
        "sequence": 20,
        "suggSubPendingPicks": false,
        "manualSubPendingPicks": false,
        "otherLocs": []
      },
      {
        "fulfillOrdNbr": 1729603,
        "ordLine": 1,
        "upc": "4011",
        "location": "A1-53-0004",
        "locId": 1,
        "locType": "SALESFLOOR",
        "availableLocsToPick": 1,
        "sequence": 22,
        "suggSubPendingPicks": false,
        "manualSubPendingPicks": false,
        "otherLocs": []
      }
    ]
  }
}
你可以用它

Xidel是一个命令行工具,用于从中下载和提取数据 HTML/XML页面以及JSON API,使用CSS、XPath 3.0、XQuery 3.0、, JSONiq或模式模板。它还可以创建新的或转换的 XML/HTML/JSON文档

XPath:

?data?pickWorkDetail?workDetail[?containers?logicalContainerNbr eq 1]?upc
xidel -s input.json -e "($json//workDetail)[.//logicalContainerNbr eq 1]/upc"
xidel -s input.json -e "$json/(.//workDetail)[.//logicalContainerNbr eq 1]/upc"
xidel -s input.json -e "$json/data/(pickWorkDetail)()/workDetail[(containers)()/logicalContainerNbr eq 1]/upc"
XQuery:

?data?pickWorkDetail?workDetail[?containers?logicalContainerNbr eq 1]?upc
xidel -s input.json -e "($json//workDetail)[.//logicalContainerNbr eq 1]/upc"
xidel -s input.json -e "$json/(.//workDetail)[.//logicalContainerNbr eq 1]/upc"
xidel -s input.json -e "$json/data/(pickWorkDetail)()/workDetail[(containers)()/logicalContainerNbr eq 1]/upc"
最新的开发快照还支持XPath/XQuery 3.1:

xidel -s input.json --xquery "for $x in $json//workDetail where $x//logicalContainerNbr eq 1 return $x/upc"

xpath用于解析XML,而不是json。请看@OldProgrammer,您没有跟上进度。XPath3.1处理JSON和XML。你指的是7年前的东西。世界在前进。