MarotReply
5 years agoNew Contributor II
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 ex...
- 5 years ago
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 sourceProperty1
to targetProp1
,Property2
to targetProp2
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.