SL12345
3 years agoNew Contributor III
Mapping (Extracting) values from xml files with mapper
Hi Snaplogic experts,
i would like to extract values from xml files. lets say:
there is a check if Value1 is object, if it is true, than do this otherwise do something else …
typeof jsonPat...
- 3 years ago
Hi @SL12345,
You can use the match operator: https://docs-snaplogic.atlassian.net/wiki/spaces/SD/pages/543621269/The+match+Control+Operator.
In your case it can be:
match typeof $Value1 { "object" => "Your logic goes here if $Value1 is an object", "array" => "Your logic goes here if $Value1 is an array", _ => "Your logic goes here if the $Value1 is neither an object nor an array" }
For example, if I have this input data:
[ { "data": { "one": 1, "two": 2 } }, { "data": [1, 2] } ]
In this case, let’s say that we want to get the key ‘one’ if the ‘data’ is an object and get the second value if the ‘data’ is an array, I can do the following:
match typeof $data { "object" => $data["one"], "array" => $data[1], _ => "" }
The output would be:
[ { "output":1 // This is from data["one"], it retrieves the value of the key 'one' }, { "output":2 // This if from data[1], it retrieves the second value from the array } ]