Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Convert CSV based on the filtering condition

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.

  1. Integer

    MEDevel.com: Open-source for Healthcare and Education

    Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

    Visit Medevel

  2. Length 5 digits

  3. 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])

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading