manohar
3 years agoContributor
To fix the pipeline to convert to array
Hi there,
I have the following JSON
[
{
"POSEX":"00010",
"E1EDPT1": [
{
"E1EDPT2": [
{
"@SEGMENT": "1",
"TDLINE": "KIT,HIGH SPEED PINION (HSP),",
"TDFORMAT": "*"
},
{
"@SEGMENT": "1",
"TDLINE": "<br/>",
"TDFORMAT": "/"
}
]
},
{
"E1EDPT2": [
{
"@SEGMENT": "1",
"TDLINE": "*NSK bearings ",
"TDFORMAT": "*"
},
{
"@SEGMENT": "1",
"TDLINE": "STF*"
}
]
}
]
},
{
"POSEX":"00020",
"E1EDPT1": {
"@SEGMENT": "1",
"E1EDPT2": [
{
"@SEGMENT": "1",
"TDFORMAT": "*"
},
{
"@SEGMENT": "1",
"TDLINE": "<br/>",
"TDFORMAT": "/"
},
{
"@SEGMENT": "1",
"TDLINE": "MATERIAL DESCRIPTION :REVERSING",
"TDFORMAT": "/"
}
]
}
}
]
And expecting following
[
{
"order-lines": [
{
"line-num": "00010",
"attachments": [
{
"text": "KIT,HIGH SPEED PINION (HSP),<br/>"
},
{
"text": "*NSK bearings STF*"
}
]
},
{
"line-num": "00020",
"attachments": [
{
"text": ",<br/>,MATERIAL DESCRIPTION :REVERSING "
}
]
}
]
}
]
I tried to build following pipeline and is not working
toArray_2023_05_29.slp (13.4 KB)
it works fine for following
[
{
"POSEX":"00010",
"E1EDPT1": {
"@SEGMENT": "1",
"E1EDPT2": [
{
"@SEGMENT": "1",
"TDFORMAT": "*"
},
{
"@SEGMENT": "1",
"TDLINE": "<br/>",
"TDFORMAT": "/"
},
{
"@SEGMENT": "1",
"TDLINE": "MATERIAL DESCRIPTION :REVERSING CONTACTOR, SOLID STATE",
"TDFORMAT": "/"
}
]
}
},
{
"POSEX":"00020",
"E1EDPT1": {
"@SEGMENT": "1",
"E1EDPT2": [
{
"@SEGMENT": "1",
"TDFORMAT": "*"
},
{
"@SEGMENT": "1",
"TDLINE": "<br/>",
"TDFORMAT": "/"
},
{
"@SEGMENT": "1",
"TDLINE": "MATERIAL DESCRIPTION :REVERSING ",
"TDFORMAT": "/"
}
]
}
}
]
and gets what expected
[
{
"order-lines": [
{
"line-num": "00010",
"attachments": [
{
"text": ",<br/>,MATERIAL DESCRIPTION :REVERSING CONTACTOR, SOLID STATE"
}
]
},
{
"line-num": "00020",
"attachments": [
{
"text": ",<br/>,MATERIAL DESCRIPTION :REVERSING "
}
]
}
]
}
]
Any help in fixing the pipeline
I created this expression that supports both object and array if that’s how the external system is sending data to Snaplogic. This will work, give it a try. You can do a little fine-tuning to this.
Let me know if this works.
toArray_2023_05_29 (1).slp (7.4 KB)
Cheers,