shancarter / mr-data-converter

Takes CSV or tab-delimited data from Excel and converts it into several web-friendly formats, include JSON and XML.
http://shancarter.github.com/mr-data-converter/
Other
1.96k stars 777 forks source link

Parse CSV with objects and arrays #42

Open kadimulam opened 8 years ago

kadimulam commented 8 years ago

I am having an issue when i parse a CSV file as shown below.

Original JSON:

{ "firstName": "John", "lastName": "Smith", "age": 25, "address": { "streetAddress": "21 2nd Street", "city": "New York", "state": "NY", "postalCode": "10021" }, "phoneNumber": [ { "type": "home", "number": "212 555-1234" }, { "type": "fax", "number": "646 555-4567" } ] }

When i use one of the tool online, it converts the above JSON to the below. firstName,lastName,age,address/streetAddress,address/city,address/state,address/postalCode,phoneNumber/0/type,phoneNumber/0/number,phoneNumber/1/type,phoneNumber/1/number John,Smith,25,25 2nd Street,New York,NY,10021,home,212 555-1234,fax,646 555-4567

I am trying to convert the above CSV file back to JSON with your tool and i am expecting the output as shown above, but it is different and converting each column header as a element in JSON.

If i want to convert a CSV file to above JSON format how should i provide the CSV to your tool? Basically my JSON can have Arrays, objects and it will be huge. Could you please advise?