CSV and JSON are the two formats you meet most often when moving data between systems. CSV comes out of spreadsheets, databases and reporting tools; JSON comes out of web APIs, configuration files and NoSQL databases. They are good at different things, and converting between them is where data quietly gets lost. This guide compares the two, explains when to use each, and shows how to convert nested JSON into a flat table safely.
CSV in one minute
A CSV (comma-separated values) file is plain text: one line per record, values separated by commas, usually with a header line naming the columns.
id,name,city,orders
1,Asha,Pune,12
2,Ravi,"Mumbai, MH",3
- Strengths: compact, human-readable, opens in every spreadsheet, streams well for millions of rows, and is understood by every database import tool.
- Weaknesses: no types (is “00123” a number or a code?), no standard for dates, no nesting, and several dialects — semicolons instead of commas, different quoting and encodings.
JSON in one minute
JSON (JavaScript Object Notation) represents data as nested objects and arrays with typed values: strings, numbers, true/false and null.
[
{ "id": 1, "name": "Asha", "address": { "city": "Pune" }, "tags": ["vip"], "orders": 12 },
{ "id": 2, "name": "Ravi", "address": { "city": "Mumbai", "state": "MH" }, "tags": [], "orders": 3 }
]
- Strengths: nesting and lists, basic types, one strict specification, and native support in every programming language and web API.
- Weaknesses: larger files (keys are repeated on every record), awkward in spreadsheets, and the whole document usually has to be parsed before use. One missing comma makes the entire file invalid.
Side by side
| Feature | CSV | JSON |
|---|---|---|
| Structure | Flat table | Nested objects and arrays |
| Types | Everything is text | String, number, boolean, null |
| Size | Small | Larger (repeated keys) |
| Opens in Excel | Directly | Needs conversion |
| Used by | Spreadsheets, BI tools, database exports | Web APIs, apps, configs, NoSQL |
| Main risk | Dialects, encodings, type guessing | Syntax errors, deep nesting |
When to use which
- Use CSV when the data is naturally a table — one row per thing, the same fields every time — and people will open it in a spreadsheet, load it into a database or chart it. Exports, reports and datasets for analysis belong here.
- Use JSON when records have different fields, contain lists or sub-objects, or are exchanged between programs. API responses, settings and event logs belong here.
- Use Excel (.xlsx) when the audience is non-technical and you need several sheets, formatting or formulas. JSON to Excel builds a workbook directly.
Converting JSON to CSV without losing data
The hard part is nesting. A table has one value per cell, so nested objects and arrays must be flattened. The usual approach is dotted column names:
id,name,address.city,address.state,tags,orders
1,Asha,Pune,,["vip"],12
2,Ravi,Mumbai,MH,[],3
Things to check after converting:
- Find the right array. API responses often wrap the records:
{ "data": { "items": [ … ] } }. Convert the array of records, not the wrapper. - Missing keys become blank cells. The CSV has the union of all keys as columns; check that sparse columns are expected.
- Arrays inside records either stay as JSON text in one cell (as above), are joined into a string, or need their own table with one row per item and a key linking back. For analysis, the separate table is usually right.
- Large numbers such as 64-bit IDs lose precision if a tool converts them to floating-point. Keep them as text.
- Types disappear. true, null and numbers become plain text in CSV; whoever reads the file has to infer them again.
SnipFerry’s JSON to CSV converter flattens nested objects with dotted keys, and its JSON formatter and validator help when the input will not parse.
Converting CSV to JSON
Going the other way is easier but involves decisions about types. Should “00123” stay a string? Should “true” become a boolean, and an empty cell null or ""? Should the result be an array of objects (most common) or an array of arrays (smaller)? Make those choices deliberately — CSV to JSON lets you turn type detection on or off — and remember that dotted headers such as address.city can be expanded back into nested objects with JSON Unflatten.
Bottom line
Store and share tables as CSV (or Excel for people) and structured, nested data as JSON. Convert at the boundary — when an API response needs to become a report, or a spreadsheet needs to feed an app — and check the result for flattened arrays, missing keys and lost types. For practical conversion steps, read How to Convert JSON to Excel and How to Import a CSV File into a SQL Database.