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"
}
}
}
}
}
}
}
这些给了我这样的o/p,
"items" : [ {
"id" : [ "1", "1" ]
}, {
"id" : [ "2", "2" ]
}, {
"id" : [ "3", "3" ]
}, {
"id" : [ "4", "4" ]
}, {
"id" : [ "5", "5" ]
}, {
"id" : [ "6", "6" ]
}, {
"id" : "7"
} ]
我正在尝试从我得到的输入中准备一个新数组,但它在每个对象中循环多次。我不确定我在哪里做错了,任何人都可以建议我帮助解决它。谢谢。
解决方案
尽管问题不清楚,但希望这是一个解决方案:
[
{
"operation": "shift",
"spec": {
"orders": {
"orderItem": {
"*": {
"lineNumber": {
"@": "items[&2].id" // @ takes value of 'lineNumber'
},
"#test": "items[&1].shipment.type" // # allows to put value 'test'
}
}
}
}
}
]
推荐阅读
- php - Slim 应用程序自动加载
- c# - 使用数据集填充 dataGridView
- python - 用另一个列表中的项目替换列表中的项目
- typescript - Angular Reactive Form Control Errors:如何读取错误对象
- openssl - 从 RSA_public_decrypt 获取解密消息?
- php - 单点登录 - 工作流程
- javascript - 解决 Promise 或在 Array push() 方法后添加回调
- javascript - How do you get selenium webdriver to return all HTML from website?
- python - 无法理解 __add__ 函数中的一些错误
- r - 计算进入和退出之间的持续时间 - 代码优化