Convert csv string to JSON object in Java

I have a csv file similar to this

"name.firstName","name.givenName","name.DisplayName","phone.type","phone.value" "john","maverick","John Maverick","mobile","123-123-123" "jim","lasher","Jim Lasher","mobile","123-123-123" 

I want to convert 2nd and 3rd lines to JSON objects. Uses the first line as the title. Thus, the result will be

 [ { "name": { "firstName": "john", "givenName": "maverick", "DisplayName": "John Maverick" }, "phone": { "type": "mobile", "value": "123-123-123" } }, { "name": { "firstName": "john", "givenName": "maverick", "DisplayName": "John Maverick" }, "phone": { "type": "mobile", "value": "123-123-123" } ] 

Any idea how to achieve this?

+4
source share
1 answer

Here is a Java library that can help you. http://www.jonathanhfisher.co.uk/playpen/csv2json/index.htm

Here is a JavaScript library that may or may not be useful to you. http://www.cparker15.com/code/utilities/csv-to-json/

And finally, here is the last answer that may be helpful. I like the OpenCSV solution. However, you can use Jackson instead of JAXB. Convert CSV file to JSON object in Java

+3
source

All Articles