json2csv icon indicating copy to clipboard operation
json2csv copied to clipboard

Possible to create 2 tables in a single csv file?

Open rochajulian opened this issue 9 months ago • 1 comments

I'd like to have one table for user account data such as email, name, etc and a SEPARATE table for their todo data such as task name, due date, etc. is this possible with this library? docs dont say so I thought to ask. This would be nice to have for sure.

rochajulian avatar Mar 10 '25 16:03 rochajulian

No.

This library, json2csv, is for changing the format of some data from json into csv.

source json

[
  {
    "email": "[email protected]",
    "name": "yes"
  },
  {
    "email": "[email protected]",
    "name": "no"
  }
]

destination csv

email,name
[email protected],yes
[email protected],no

You haven't said why you want to have multiple tables in one csv.

As an illustration, I'm going to imagine you want to open the csv in Excel as a sheet, and that you want two tables to appear on the one sheet.

You would have to take your user account json data and use json2csv convert it to csv:

user account json data

[
  {
    "email": "[email protected]",
    "name": "yes"
  },
  {
    "email": "[email protected]",
    "name": "no"
  }
]

user account csv data

email,name
[email protected],yes
[email protected],no

Then you would take your todo task json data and use json2csv to convert that to csv:

todo task json data

[
  {
    "task": "drive home",
    "date": "01/01/1979"
  },
  {
    "task": "quit job",
    "date": "02/01/1979"
  },
  {
    "task": "go on holiday",
    "date": "03/01/1979"
  }
]

todo task csv data

task,date
drive home,01/01/1979
quit job,02/01/1979
go on holiday,03/01/1979

Then you would need to write some code to make a larger csv, with an appropriate number of rows and columns and shift one table into the correct position:

combined into a double table csv

email, name,,,task,date
[email protected],yes,,,drive home,01/01/1979
[email protected],no,,,quit job,02/01/1979
,,,,go on holiday,03/01/1979

Opened in Excel, it would look like this:

Image

a.csv

oliverfoster avatar Mar 10 '25 17:03 oliverfoster