CSV vs JSON: Choosing the Right Data Format
CSV and JSON both store data as text, but they model it differently. CSV is a table; JSON is a tree. Picking the one that matches the shape of your data avoids a lot of conversion pain later.
The same records, both ways
id,name,city,orders
1,Ada,London,12
2,Grace,New York,7[
{ "id": 1, "name": "Ada", "city": "London", "orders": 12 },
{ "id": 2, "name": "Grace", "city": "New York", "orders": 7 }
]For flat, uniform rows CSV is dramatically more compact — the field names appear once instead of on every record. Add one nested field and that advantage disappears.
Comparison
| Aspect | CSV | JSON |
|---|---|---|
| Structure | Flat table only | Arbitrary nesting |
| Size (flat data) | Smallest | 2–4× larger |
| Types | Everything is a string | Numbers, booleans, null, arrays |
| Streaming | Line by line, trivially | Needs a streaming parser or NDJSON |
| Spreadsheet support | Native | Requires conversion |
| Schema | Header row only, by convention | JSON Schema available |
| Escaping | Quoting rules with dialect variation | Well specified |
| Human readability | Excellent for tables | Excellent for records |
CSV's rough edges
- There is no single CSV standard — separators, quoting and line endings all vary
- Locales that use a comma as the decimal separator often export semicolon-delimited files
- Fields containing commas, quotes or newlines must be quoted, and quotes doubled inside
- Leading zeros and long identifiers are mangled by spreadsheet auto-typing
- Character encoding is not declared in the file, so UTF-8 is frequently misread
Never split CSV lines on commas with a simple string split. A quoted field can legally contain commas and newlines. Use a real parser.
Choosing between them
- Use CSV for tabular exports, spreadsheet handoff, bulk database loads and analytics files
- Use JSON for API payloads, configuration, nested records and anything with optional fields
- Use NDJSON — one JSON object per line — when you want JSON's structure with CSV's streamability
- Use Parquet instead of both when datasets grow into the gigabytes
Converting between them
JSON to CSV requires flattening: nested objects become dotted column names such as address.city, and arrays either become indexed columns or a joined string. Both are lossy in the sense that the original shape has to be reconstructed by convention. CSV to JSON is simpler, but every value arrives as a string, so types must be inferred or declared.
{ "id": 1, "address": { "city": "London" }, "tags": ["a","b"] }
id,address.city,tags
1,London,"a|b"CSV to JSON
Convert CSV to a typed JSON array with delimiter detection, in the browser.
Common mistakes
Opening a CSV in a spreadsheet and re-saving it
Auto-formatting silently converts identifiers to dates and strips leading zeros. Import as text instead.
Assuming the delimiter is a comma
Detect it. Semicolons and tabs are extremely common in exports from European systems.
Loading a huge JSON array into memory
Use NDJSON so records can be processed one line at a time.
Flattening without documenting the convention
If consumers do not know how nesting was encoded, the data cannot be reconstructed reliably.
Frequently asked questions
Is CSV smaller than JSON?
For flat, uniform data, considerably — field names are stored once. For nested or sparse data the gap closes or reverses.
Can CSV store nested data?
Not natively. Nesting has to be flattened into dotted column names or serialised into a single field, which both rely on convention.
Which format is better for large datasets?
CSV or NDJSON, because both stream line by line. A single large JSON array must usually be parsed in full.
Does CSV preserve data types?
No. Every field is text, so consumers infer or declare types. This is the main reason exports lose leading zeros.
Put this into practice
CSV to JSON runs entirely in your browser — no upload, no account, no limits.
Open CSV to JSONRelated tools
Related guides
JSON vs XML: Which Format Should You Use?
A practical JSON vs XML comparison: syntax, size, parsing speed, schemas, comments, attributes and metadata — plus clear guidance on which format fits which job.
How to Convert CSV to JSON Correctly
Convert CSV to JSON without losing data: handling delimiters, quoted fields, headers, type inference, empty values, encodings and nested output structures.
What Is JSON? A Plain-English Guide
JSON explained without jargon: what it is, how the syntax works, which data types it supports, where it is used and how it differs from JavaScript objects.
PNG vs JPG vs WebP: Which Image Format to Use
Compare PNG, JPG, WebP and AVIF on compression, transparency, quality and browser support, with a simple decision guide for photos, screenshots, logos and animation.
How to Compress a PDF Without Wrecking the Quality
Understand what actually makes a PDF large, which compression settings matter, how much size you can realistically save, and how to compress a PDF privately in your browser.
How to Format JSON (Beautify, Indent and Minify)
Learn how JSON formatting works, see a before-and-after example, fix the errors that block beautifying, and format JSON online in your browser without uploading a file.