Working with tabular data? JSON vs CSV strings?

I am building a plugin for Wordpress that uses Ag-Grid as a UI to manipulate a data table. The user would be creating several (maybe dozens, hundreds?) of different tables, so storing them each as their own sql table isn’t feasible.

I suppose at this point I’m left with storing the data either as JSON or strings that represent a csvs.

The prototype I’ve built uses JSON like

[
    {
        "Department":"Sheriff",
        "Budget":100000,
        "MeetAt":"2025-01-26T14:30:00Z",
        "preferredColor":"red",
        "PostContent":"<div> </div>"
    },
    {
        "Department":"Assessor",
        "Budget":20000,
        "MeetAt":"2025-01-26T14:30:00Z",
        "preferredColor":"#232323",
        "PostContent":"<div> </div>"
    },
    {
        "Department":"Treasurer",
        "Budget":30000,
        "MeetAt":"2025-01-26T14:30:00Z",
        "preferredColor":"#E72323",
        "PostContent":"<div> </div>"
    }
]

where each of the keys in the objects represents a column in the table (which means each object represents a row).

CSV strings kind of make more sense to my brain, but I suspect that that would lead mean it would be easier to screw up the integrity of the data.

What’s the typical way of working with tabular data in javascript?

1 Like

Personally I don’t see an issue with that, the only thing I would want to add is a unique row id e.g. department_id.

I’m not sure it is particularly good practice to use array indexes for row ids. If the array is sorted or rows are inserted the rows will no longer have the same ids. If that makes sense.

1 Like