CSV vs JSON: flat tables or nested data?
CSV and JSON both store data as text, but one is a flat grid and the other is a tree. Choosing wrong means either awkward nesting or bloated, hard-to-edit files.
| CSV | JSON | |
|---|---|---|
| Shape | Flat rows and columns | Nested objects and arrays |
| Nesting | None (one level) | Arbitrary depth |
| Spreadsheet tools | Opens natively | Needs conversion |
| File size | Compact | Larger (repeats keys) |
| Type info | Everything is a string | Strings, numbers, booleans, null |
| Best for | Tabular exports, analytics | APIs, config, nested records |
Flat vs nested
CSV is a grid: one row per record, one column per field. It is unbeatable for tabular data you will open in Excel or load into a data warehouse. But it has no concept of nesting — represent a list-within-a-record and you are inventing conventions.
JSON handles nested and irregular data natively, which is why APIs use it. The cost is size (keys repeat on every object) and that spreadsheets cannot open it directly.
Converting between them
Flat JSON (an array of flat objects) maps cleanly to CSV. Deeply nested JSON does not — you must flatten or pick columns first. The JSON ↔ CSV converter handles the common flat case in your browser.
The verdict
Use CSV for flat, tabular data headed to a spreadsheet or analytics pipeline. Use JSON for nested records, APIs, and config. Moving between them? The JSON ↔ CSV tool does it instantly.
Frequently asked questions
- Can any JSON be converted to CSV?
- Only flat JSON (an array of objects with simple values) maps cleanly. Nested JSON must be flattened or have columns selected first, since CSV cannot represent nesting.
- Why is CSV smaller than JSON?
- CSV writes column names once in a header row. JSON repeats every key in every object, so equivalent data is larger.
- Does CSV preserve data types?
- No. Every CSV value is text; the consumer decides how to interpret it. JSON distinguishes strings, numbers, booleans, and null.
Try it yourself
Free, in-browser tools for everything above.