I have complex (EDI) input that looks like this:
{
"INS-2000_loop": [
{
"INS_05": "A",
"INS_06": "D",
"INS_08": "AC"
},
{
"REF_01": "0F",
"REF_02": "111111111"
},
{
"NM1-2100A_loop": [
{
"NM1_01": "IL",
"NM1_02": "1",
"NM1_03": "aaa",
"NM1_04": "bbb"
},
{
"PER_03": "HP",
"PER_04": "1234567890"
}
]
},
{
"HD-2300_loop": [
{
"HD_01": "001",
"HD_03": "HMO",
"HD_04": "485-014-000",
"HD_05": "IND"
},
{
"DTP_01": "348",
"DTP_02": "D8",
"DTP_03": "20240401"
}
]
},
{
"HD-2300_loop": [
{
"HD_01": "001",
"HD_03": "HMO",
"HD_04": "485-014-000",
"HD_05": "IND"
},
{
"DTP_01": "348",
"DTP_02": "D8",
"DTP_03": "20240101"
},
{
"DTP_01": "349",
"DTP_02": "D8",
"DTP_03": "20240331"
}
]
}
]
}
The input can have any number of HD-2300_loop
elements (typically less than 5) and only one INS-2000_loop
element. I want the HD-2300_loop
elements to "drive" the output so that output is an array of complex objects of the same length as the number of HD-2300_loop
elements. The complex objects of the output array need to have all the data in the HD-2300_loop
elements and the data of all the children of the INS-2000_loop
element except the HD-2300_loop
looking like this:
[
{
"L2300": [
{
"HD_01": "001",
"HD_03": "HMO",
"HD_04": "485-014-000",
"HD_05": "IND"
},
{
"DTP_01": "348",
"DTP_02": "D8",
"DTP_03": "20240101"
},
{
"DTP_01": "349",
"DTP_02": "D8",
"DTP_03": "20240331"
}
],
"L2000": [
{
"INS_05": "A",
"INS_06": "D",
"INS_08": "AC"
},
{
"REF_01": "0F",
"REF_02": "111111111"
},
{
"NM1-2100A_loop": [
{
"NM1_01": "IL",
"NM1_02": "1",
"NM1_03": "aaa",
"NM1_04": "bbb"
},
{
"PER_03": "HP",
"PER_04": "1234567890"
}
]
}
]
},
...
]
I’ve started with the following spec which isn’t giving what I want – I haven’t figured out how to inject the @3
selection into the result of the @1
selection. Also, I haven’t figure out how to rename the selection results (to L2300
and L2000
) and how to skip the HD-2300_loop
child in the @3
selection result.
[
{
"operation": "shift",
"spec": {
"*": {
"*": {
"HD-2300_loop": {
"@1": "",
"@3": ""
}
}
}
}
}
]
I would also greatly appreciate if anyone could point me a Jolt doc or cheat sheet that explains how the &
operators work. Thanks very much.
2
Answers
Here's the final solution I came up with (includes some transformations not mentioned in the original problem):
Hi this spec will help you resolve the query :
Explaination:
As for am keeping the things as normal required list.
From "HD-2300_loop" am taking all attributes and keeping them in new array "L2300" and rest fields in "L2000".
In this operation am creatin a unique key based on attributes present in each L2300 object to eliminate duplicates.
{
"operation": "shift",
"spec": {
"": {
"": "&",
"L2300": {
"": "test.@key[]"
}
}
}
}, {
"operation": "cardinality",
"spec": {
"test": {
"": "ONE"
}
}
}
This 3 specs are used to remove dublicate attributes from the L2300 list.
{
"operation": "shift",
"spec": {
"": "[#2].&",
"test": {
"": {
"@": "[#4].L2300.[]"
}
}
}
}, {
"operation": "remove",
"spec": {
"": {
"": {
"*": {
"key": ""
}
}
}
}
}
Last 2 operations are to create required structure.
For Jolt Documentation of # and & you can explore Digibee documentations :
https://docs.digibee.com/documentation/components/tools/transformer-jolt/transformer-getting-to-know-jolt