• Post Reply Bookmark Topic Watch Topic
  • New Topic

Convert JSON Hashmap to CSV

 
vivek dhiman
Ranch Hand
Posts: 153
Netbeans IDE Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I have json of below structure : List<Map>


I need to convert it to CSV file as below:


I am not able to get how to handle blank values, as json is dynamic and new values can be added in future.

Thanks
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 35716
412
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Vivek,
Do you have a list of all the column headers you want in your CSV? If so, it is "just" a matter of reading the JSON and writing to a data structure. If not, you could read the file into memory and go through it twice - once to build a Set of header names and again to actually write.

I recommend you use Apache Commons CSV or Open CSV for the actually writing to CSV part. For reading the CSV, I like GSON, but there are many good libraries.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!