06-21-2023 06:19 PM
I am working on an integration between two endpoints that deal with values in very different ways and I’m struggling to convert between them. The source I’m getting data from sends out data with mutliple values all on the same element so my input document looks like this
[
{
"Key": "V1,V2,V3"
},
{
"Key": "V1"
},
{
"Key": "V1"
},
{
"Key": "V1,V2,V3,V4"
}
]
but my output document needs to look like this
[
{
"keys": [
{
"key": {
"id": "V1"
}
},
{
"key": {
"id": "V2"
}
},
{
"key": {
"id": "V3"
}
}
]
},
{
"keys": [
{
"key": {
"id": "V1"
}
}
]
},
{
"keys": [
{
"key": {
"id": "V1"
}
}
]
},
{
"keys": [
{
"key": {
"id": "V1"
}
},
{
"key": {
"id": "V2"
}
},
{
"key": {
"id": "V3"
}
},
{
"key": {
"id": "V4"
}
}
]
}
]
Does anyone have suggestions for a good way to deal with this conversion? Due to the variable length of each document I’m thinking I might need to use a child pipeline so I can build the output JSON element by element, but I’m not sure if that’s the best way to go about this
Solved! Go to Solution.
06-22-2023 04:46 AM
Thanks for the help! That didn’t get me all the way there, but after looking at it I realized I could use another map to get the values I needed. In the end I did this
$Key.split(',').map(x=>{"id":x}).map(x=>{"key":x})
which got me the exact output I was looking for
06-21-2023 11:07 PM
Hi @maddog0,
Try and map the following expression in a Mapper:
{"key":$Key.split(',').map(x=>{"id":x})}
With target path keys
Let us know if this helps.
Regards,
Bojan
06-22-2023 04:46 AM
Thanks for the help! That didn’t get me all the way there, but after looking at it I realized I could use another map to get the values I needed. In the end I did this
$Key.split(',').map(x=>{"id":x}).map(x=>{"key":x})
which got me the exact output I was looking for