1

I have JSON data in the following form:

{
  field: ...,
  field: ...,
  field: ...,
  field: ...,
  items: [{array of multiple objects}]
},
{
  field: ...,
  field: ...,
  field: ...,
  field: ...,
  items: [{array of multiple objects}]
},
{
  field: ...,
  field: ...,
  field: ...,
  field: ...,
  items: [{array of multiple objects}]
}
...

and so on. I want to convert it into CSV for report generation, but I'd like each item in that array to have its own row like this.

Since I'm building the webapp using VueJS and Firebase, is there any way I can convert and have a downloadable CSV file, through Javascript?

  • Possible duplicate of [How to convert JSON to CSV format and store in a variable](https://stackoverflow.com/questions/8847766/how-to-convert-json-to-csv-format-and-store-in-a-variable) – Hyyan Abo Fakher Jul 24 '18 at 11:53
  • See the link of @HyyanAboFakher to create your csv content in a string, then you can have a look at the following link on how to create a downloadable file (pure JS): https://ourcodeworld.com/articles/read/189/how-to-create-a-file-and-generate-a-download-with-javascript-in-the-browser-without-a-server – Cinn Jul 24 '18 at 11:58
  • Hey, I'm able to get everyhing in one row, but I'd like to take it further and have each item in items in its own row, like in the image. How can I do that? Would I have to create a new row and set the earlier fields to " "? – freeribosome Jul 24 '18 at 16:51
  • @freeribosome Can you provide the code you already did so we can help you from where you are? – Cinn Jul 24 '18 at 21:44
  • Here's what I have so far: [Link](https://gist.github.com/kunmishra2599/48e2196fee0396e5df91cd6a7f24d98b) – freeribosome Jul 25 '18 at 06:52
  • So you want 1 object by row, 1 field by column, and for the array of multiple object they are placed in a same column? – Cinn Jul 25 '18 at 08:30
  • It wouldn't really be one object by row, since multiple items moves it down to multiple rows, but yes that's the general idea. – freeribosome Jul 26 '18 at 05:00

0 Answers0