Could some one please help me to map the below csv to JSON.
Need to filter based on the below filtering condition on all the five fields.
-
Integer
-
Length 5 digits
-
First two digits starts with “65”
Input:
field1,field2,field3,field4,field5
123,ABC12,4512300000,234,567
567,4532100000,DEF34,123,432
Output:
[
{
"OrderNUmber": "4512300000"
},
{
"OrderNUmber": "4532100000"
}
]
>Solution :
I am think that there will be just one field in each row that matches all three conditions, hence selector [0]
%dw 2.0
output application/json
import * from dw::Runtime
fun isNumber(value): Boolean = try(() -> isInteger(value)) orElse false
payload map ((item, index) ->
OrderNumber: (valuesOf(item)
filter (( value ) -> (isNumber(value)
and (value startsWith "65")
and sizeOf(value) == 5)))[0])