如何在JOLT中准备阵列?

时间:2018-07-27 12:41:41

标签: json jolt

我正在尝试从输入中准备一个新数组,但是它在每个对象中循环多次。

我有这样的输入

  {
"orders": {
  "orderItem": [
  {
    "shipperRef": null,
    "productID": "5150002516",
    "lineNumber": 1,
    "description": "SM UNCRSTBL PB&GRP 4-PK 8CT CS",
    "packageQuantity": 198,
    "packageType": {
      "description": "CASE",
      "edicode": "CAS"
    },
    "weight": 1108.8,
    "netWeight": null,
    "volume": 108.5,
    "commodity": {
      "description": "0 DEGREES OR LOWER",
      "shortDesc": null,
      "freightClass": "FAK",
      "temperatureClass": "FROZEN",
      "trailerTypes": {
        "trailerType": [
          "REEFER"
        ]
      },
      "hazmat": "No"
    },
    "ladingQuantity": 3,
    "ladingType": {
      "description": "PALLET",
      "edicode": "PLT"
    },
    "valuationRate": null,
    "valuationTotal": null

      ]
    },
    "billableItemAllocationDetails": null
  },
  {
    "shipperRef": null,
    "productID": "5150002517",
    "lineNumber": 2,
    "description": "SM UNCRSTBL PB&STR 4-PK 8CT CS",
    "packageQuantity": 132,
    "packageType": {
      "description": "CASE",
      "edicode": "CAS"
    },
    "weight": 739.2,
    "netWeight": null,
    "volume": 77.35,
    "commodity": {
      "description": "0 DEGREES OR LOWER",
      "shortDesc": null,
      "freightClass": "FAK",
      "temperatureClass": "FROZEN",
      "trailerTypes": {
        "trailerType": [
          "REEFER"
        ]
      },
      "hazmat": "No"
    },
    "ladingQuantity": 2,
    "ladingType": {
      "description": "PALLET",
      "edicode": "PLT"
    },
    "valuationRate": null,
    "valuationTotal": null,
    "payableItemAllocationDetails": {
      "itemAllocationDetail": [
        {
          "chargeCodeID": "BAS",
          "chargeCodeDesc": "BA"
        },
        {
          "chargeCodeID": "405",
          "chargeCodeDesc": "FUEL SURCHARGE",
          "currencyCode": "USD",
          "payableAllocation": 4.05,
          "segment1": "510",
          "segment2": null,
          "segment3": null,
          "segment4": null,
          "segment5": null,
          "segment6": null
        }
      ]
    },
    "billableItemAllocationDetails": null
  }
]
 }
 }

此处显示的输出为

 {
 "items": [
  {
  "id": 1,
  "shipment": {
    "type": "test"
  }
},
{
  "id": 2,
  "shipment": {
    "type": "test"
  }
},
{
  "id": "3",
  "shipment": {
    "type": "test"
  }
 }
]}

我的物种,

 {
"orders": {
 "order": {
   "*": {
    "orderItems": {
      "orderItem": {
        "*": {
          "lineNumber": "items[&1].id"
        }
      }
      }
    }
  }
 }
}

这些给我这样的机会,

"items" : [ {
  "id" : [ "1", "1" ]
  }, {
   "id" : [ "2", "2" ]
  }, {
  "id" : [ "3", "3" ]
   }, {
   "id" : [ "4", "4" ]
   }, {
  "id" : [ "5", "5" ]
   }, {
   "id" : [ "6", "6" ]
   }, {
   "id" : "7"
   } ]

我正在尝试从输入中准备一个新数组,但是它在每个对象中循环多次。 我不确定我做错了什么地方,谁能建议我帮忙解决。谢谢。

1 个答案:

答案 0 :(得分:0)

尽管有一个不清楚的问题,希望它是一个解决方案:

    [
      {
        "operation": "shift",
        "spec": {
          "orders": {
            "orderItem": {
              "*": {
                "lineNumber": {
                  "@": "items[&2].id" // @ takes value of 'lineNumber'
                },
                "#test": "items[&1].shipment.type" // # allows to put value 'test'
              }
            }
          }
        }
      }
    ]