Conditional filtering in Mule Dataweave %1.0
You can use the filter function to filter your array.
%dw 1.0%output application/json---{ output: payload.source filter ($.value.Type[0].code == "SEC")}
the above code will produce the following output:
{ "output": [ { "value": { "Type": [ { "val": "Secondary", "code": "SEC" } ], "Value": [ { "val": "HOSP", "Code": "Hospital" } ] } } ]}
Amendment: Here is the new piece of code which will give you only the value you are looking for and not the whole Array
%dw 1.0%output application/json skipNullOn="everywhere"---{ (payload.source default [] map (source, indexOfSource) -> { output: source.value.Value[0].val when source.value.Type[0].code == "SEC" otherwise null }) }
The output of the above piece of code is:
{ "output": "HOSP"}