AnsweredAssumed Answered

CSV structure to JSON format. Generating Repeating segments in JSON

Question asked by navin_zachariah Employee on Mar 13, 2017
Latest reply on Mar 14, 2017 by Lee Sobotkin

Community Forums

I've a requirement to convert CSV structure to JSON format. Need some guidance in acheiving the below shown JSON output

Last field value in CSV file(CARDID) is seperated by semicolon(;)and it can happen n number of times.

Basically an employee can have multiple card id's. When the JSON output gets created, only the tokens segment has to be repeated with the cardid's and the common records should not be repeated.

I'm not able to figure out how can I generate repeating segments depending on the number of id's in the source field.

 

Source CSV file

EMPLOYEE_NUMBER,FIRST_NAME,LAST_NAME,CARDID
9007405,John,Smith,11
9012550,Bart,Simpson,7;8

 

Output JSON expected


[
{
"employee_id": 9007405,
"name": "John Smith",
"tokens": {
"number": 11,
"type": "Access Control"
},
},
{
"employee_id": 9012550,
"name": "Bart Simpson",
"tokens": [
{
"number": 7,
"type": "Access Control"
},
{
"number": 8,
"type": "Access Control"
}],
}
]


Expecting your help in solving this.

Thanks,
Navin

Outcomes