• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
  • Campbell Ritchie
  • Liutauras Vilda
  • Bear Bibeault
  • Tim Cooke
  • Junilu Lacar
  • Paul Clapham
  • Devaka Cooray
  • Knute Snortum
Saloon Keepers:
  • Ron McLeod
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Frits Walraven
  • Carey Brown
  • salvin francis
  • Claude Moore

Convert csv to JSON  RSS feed

Ranch Hand
Posts: 69
Firefox Browser Java Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi ,

I am trying to convert data from a csv file to json format.Search on the internet told me that we need to use external libraries.But all the samples that i found had headers included in the CSV file.But I do not have the headers in my CSV file.So I do not know how to parse.
Below is the sample data in CSV :


I need the data in below format :
Data [{

Here "ColumnA","ColumnB", and so on are some constants(we can say as hardcoded values).
Not sure if any external lib is required for this or we can do this with no String operations.
Here is the code i have so far :

Any help is welcome.
Thanks Udaya
Saloon Keeper
Posts: 20657
Android Eclipse IDE Java Linux Redhat Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You do not need external libraries. Printing JSON can be done without external support methods, though for more complex applications, there are external libraries that can help. For your problem, they're not worth the trouble.

You could use an external library to parse the CSV more reliably. Using a Scanner to split the columns is fine for a file full of numbers and/or simple text, but when you have columns that have quotes and/or commas as part of the column value, that's when you'd want an external library that already knows how to do that - it saves design and coding time to add that extra logic and some other poor slob has already done the debugging.

So you're fine as-is.
please buy this thing and then I get a fat cut of the action:
Create Edit Print & Convert PDF Using Free API with Java
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!