Forum Discussion
I haven’t yet found a solution, so yes.
Also here are the formatted JSONS:
Received JSON:
{
"Property1":"value1",
"Property2":"value2",
"Property3":"value3",
"Subarray":[
{
"SubProperty1":"subValue1",
"SubProperty2":"SubValue2",
"SubProperty3":"SubValue3"
},
{
"SubProperty1":"subValue4",
"SubProperty2":"SubValue5",
"SubProperty3":"SubValue6"
}
]
}
Should be Produced JSON:
{
"Prop1":"value1",
"Prop2":"value2",
"MyArray":[
{
"SubProp1":"subValue1",
"SubProp2":"SubValue2",
},
{
"SubProp1":"subValue4",
"SubProp2":"SubValue5",
}
]
}
I have found that I can manipulate the subArrays by using a JSON splitter and working on each one individually, I have not however found out how to use the join snap to properly put them back into the required space once this is done.
you can use the match operator to match the each doc in the array and map it to whatever you’d like
so using this expression:
$Subarray.map(entry => match entry { {SubProperty1, SubProperty2} => {"SubProp1": SubProperty1, "SubProp2": SubProperty2}, _ => []})
mapped to MyArray should give you the desired output for the nested array portion. The rest seems to just be direct mappings from source Property1 to target Prop1, Property2 to target Prop2 while setting pass through to off.
One thing to note, the ‘_’ is used as a default incase there is a document that does not match any of the arms in the match. So, if there is a doc that does not have these fields it would default to an empty array, which you can change.
- MarotReply5 years agoNew Contributor II
Thank you, this solutions seems to work!