Mappping element of a Subarray of a JSON document in mapper snap
Hello, I have an issue with splitting a JSON document in a mapper.
In short, this document is received via a REST Get Snap and certain elements of it should be mapped to certain names, think for example:
Received JSON:
{
“Property1”:“value1”,
“Property2”:“value2”,
“Property3”:“value3”,
“Subarray”:[
{
“SubProperty1”:“subValue1”,
“SubProperty2”:“SubValue2”,
“SubProperty3”:“SubValue3”
},
{
“SubProperty1”:“subValue4”,
“SubProperty2”:“SubValue5”,
“SubProperty3”:“SubValue6”
}
]
}
And the produced JSON should look something like this:
{
“Prop1”:“value1”,
“Prop2”:“value2”,
“MyArray”:[
{
“SubProp1”:“subValue1”,
“SubProp2”:“SubValue2”,
},
{
“SubProp1”:“subValue4”,
“SubProp2”:“SubValue5”,
}
]
}
In and of itself, this should be a simple task, we have only to map some input values to some output values. However when mapping the values in the subarray like so:
$ SubProperty1 → $Prop1
$ SubProperty2 ->$Prop2
jsonPath($, "$SubArray[].SubProperty1") → $MyArray[].SubProp1
instead of producing the second JSON as required it produces something like this:
{
“Prop1”:“value1”,
“Prop2”:“value2”,
“MyArray”:[
{
“SubProp1”:[
“subValue1”,
“subValue4”
],
“SubProp2”:[
“SubValue2”,
“SubValue5”
]
}
]
}
So it seems that instead of splitting the values of the elements in SubArray between the elements in MyArray, it sees the array of the elements as one unit and therefore populates only the first element in MyArray with a vector containing the elements of SubArray.
I’ve been trying various things but I can’t seem to solve this, any help would be appreciated.
Note that since the data comes from a Rest Call, snaplogic doesn’t know until execution what the data should look like.
I hope that was clear, the problem itself is rather simple but the explanation is somehow a little complicated.
Thanks in advance!