Home > Software engineering >  Json to csv conversion in Spring boot
Json to csv conversion in Spring boot

Time:04-19

I have a csv structure like this

enter image description here

and I also have one json response

    [
 {
  "ID"   : "1",
  "Name" : "abc",
  "Mobile" : "123456"
   },
   {
  "ID"   : "2",
  "Name" : "cde",
  "Mobile" : "123345"
   }
   ]

I need the output like this

enter image description here

CodePudding user response:

You can do it using jackson-dataformat-csv
Refer this post https://www.baeldung.com/java-converting-json-to-csv

CodePudding user response:

If your intention is to convert directly the JSON then that baeldung solution that you were given is good.

Otherwise, the way i see it and based on the info you're giving, you will need to have a representation of that JSON in a java object that will either represent some kind of request coming from somewhere or data you're getting from your database in order to be written on a csv.

Check out these, might be useful: https://www.codejava.net/frameworks/spring-boot/csv-export-example

https://zetcode.com/springboot/csv/

  • Related