输入 :
{
"values": [
{
"reference_id": "TEST_51_ST",
"idoc_number": "0000000113916030",
"sto_number": "",
"sending_location": "0000000625",
"receiving_location": "4955",
"idoc_status": "51",
"create_time": "07:19:34",
"create_date": "2023-07-20",
"values1": [
{
"material_number": "A17265420",
"status": "E",
"message_class": "06",
"message_num": "215",
"message_text": "Please enter net price"
},
{
"material_number": "",
"status": "E",
"message_class": "BAPI",
"message_num": "001",
"message_text": "No instance of object type PurchaseOrder has been created. External reference:"
}
]
},
{
"reference_id": "TEST_51_ST123",
"idoc_number": "0000000113916030312",
"sto_number": "",
"sending_location": "00000006253",
"receiving_location": "49553",
"idoc_status": "513",
"create_time": "07:19:34",
"create_date": "2023-07-20",
"values1": [
{
"material_number": "A172654203",
"status": "E",
"message_class": "06",
"message_num": "2153",
"message_text": "Please enter net price"
},
{
"material_number": "",
"status": "E",
"message_class": "BAPI",
"message_num": "0031",
"message_text": "No instance of object type PurchaseOrder has been created. External reference:"
}
]
}
]
}
预期输出:
[
{
"reference_id": "TEST_51_ST",
"idoc_number": "0000000113916030",
"sto_number": "",
"sending_location": "0000000625",
"receiving_location": "4955",
"idoc_status": "51",
"create_time": "07:19:34",
"create_date": "2023-07-20",
"material_number": "A17265420",
"status": "E",
"message_class": "06",
"message_num": "215",
"message_text": "Please enter net price"
},
{
"reference_id": "TEST_51_ST",
"idoc_number": "0000000113916030",
"sto_number": "",
"sending_location": "0000000625",
"receiving_location": "4955",
"idoc_status": "51",
"create_time": "07:19:34",
"create_date": "2023-07-20",
"material_number": "",
"status": "E",
"message_class": "BAPI",
"message_num": "001",
"message_text": "No instance of object type PurchaseOrder has been created. External reference:"
},
{
"reference_id": "TEST_51_ST123",
"idoc_number": "0000000113916030312",
"sto_number": "",
"sending_location": "00000006253",
"receiving_location": "49553",
"idoc_status": "513",
"create_time": "07:19:34",
"create_date": "2023-07-20",
"material_number": "A172654203",
"status": "E",
"message_class": "06",
"message_num": "2153",
"message_text": "Please enter net price"
},
{
"reference_id": "TEST_51_ST123",
"idoc_number": "0000000113916030312",
"sto_number": "",
"sending_location": "00000006253",
"receiving_location": "49553",
"idoc_status": "513",
"create_time": "07:19:34",
"create_date": "2023-07-20",
"material_number": "",
"status": "E",
"message_class": "BAPI",
"message_num": "0031",
"message_text": "No instance of object type PurchaseOrder has been created. External reference:"
}
]
需要一个 jolt 规范来解决这个问题,尝试了这个 jolt,但它只对一个数组元素起作用
[
{
"operation": "shift",
"spec": {
"values": {
"*": {
"values1": {
"*": {
// Extract fields from the main object along with each `values1` item
"@(2,reference_id)": "[&1].reference_id",
"@(2,idoc_number)": "[&1].idoc_number",
"@(2,sto_number)": "[&1].sto_number",
"@(2,sending_location)": "[&1].sending_location",
"@(2,receiving_location)": "[&1].receiving_location",
"@(2,idoc_status)": "[&1].idoc_status",
"@(2,create_time)": "[&1].create_time",
"@(2,create_date)": "[&1].create_date",
// Map each field within `values1`
"material_number": "[&1].material_number",
"status": "[&1].status",
"message_class": "[&1].message_class",
"message_num": "[&1].message_num",
"message_text": "[&1].message_text"
}
}
}
}
}
}
]
但无法正常工作。它适用于这种有效负载直接父引用(@(3, ...))
:values1 之外的每个父字段(如 reference_id、idoc_number 等)在第 3 级(相对于 values1)访问,确保每个 values1 项都生成具有唯一父值集的对象。唯一的扁平化条目([&2])
:values1 数组元素分别被扁平化为不同的对象,因此输出 JSON 对于每个 values1 元素都有独立的条目,而无需将字段分组到数组中。预期输出这应该为每个 values1 条目生成一个包含 reference_id、idoc_number、material_number 等字段的不同对象列表,而无需将值组合成数组。如果这提供了所需的格式,请告诉我