• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Convert JSON Hashmap to CSV

 
Ranch Hand
Posts: 157
Netbeans IDE Tomcat Server
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
author & internet detective
Posts: 41860
908
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
reply
    Bookmark Topic Watch Topic
  • New Topic