Forum Discussion

Igor_Bozhinovsk's avatar
Igor_Bozhinovsk
New Contributor III
3 years ago
Solved

Map Json Structure

Currently we have json data like this :
{
“Test”: “1”
“SerialNumbers”: {
“SerialNo”: [
“123”,
“456”
]
}

The desired output is like this:
{
“Test”: “1”
“SerialNumbers”: [
{“SerialNo”: “123”},
{“SerialNo”: “456”}
]
}

Is there any function we could use to achive this in SnapLogic ?

  • You might be able to get around it by using the following expression in a mapper before trying to process the $messages value:

    sl.ensureArray($messages)

    This way, if it is a single object, it will be a single-entry array. If it is already an arrary, it simply passes through.

1 Reply

  • bubba's avatar
    bubba
    New Contributor

    Much thanks for your feedback. I’m still testing but it’s now working as expected as far as I can see.