Pular para o conteúdo principal

JSON vs CSV

Pick CSV for flat, row-shaped data headed for spreadsheets, bulk imports or column-oriented tools — it streams cheaply and opens everywhere. Pick JSON when records nest, types matter, or a program consumes the payload. CSV is a table and JSON is a tree; convert whenever the consumer changes, not the data.

Só local

O guia abaixo está disponível apenas em inglês.

JSON vs CSV explained

CSV is the format data arrives in from the physical world: spreadsheet exports, bank statements, sensor dumps, CRM downloads. It looks trivially simple — values separated by commas — and that apparent simplicity is exactly why it is mishandled so often. RFC 4180 defines a precise quoting discipline that most real files follow loosely, and dialects multiply from there. JSON, by contrast, is the format programs exchange with each other: one small grammar, six types, and nesting as deep as the data needs.

The essential difference is shape. A CSV file is a two-dimensional table: rows of columns, one value per cell, and everything is text. A JSON document is a tree: objects inside arrays inside objects, with each value carrying its own type. Neither is better; they answer different questions. But most conversion pain — and most badly broken conversions — come from forcing a tree into a table, or pretending a table has structure it does not.

This page compares them where decisions actually happen: structure, typing and quoting, Excel behaviour, bulk size and streaming. Both conversion directions are linked below and run entirely in your browser, with the flattening and type-inference rules documented rather than hidden.

Turning an API response into something an analyst can open is the classic crossing — the JSON to CSV converter flattens an array of records into columns in one paste, entirely in your browser.

Ingesting a vendor's spreadsheet export into code? The CSV to JSON converter adds types and structure locally, before the file ever reaches your parser.

Shape: one table versus a tree

A CSV file is a sequence of records, each the same width: name, email, amount, repeated for every row. A header row — conventional, not guaranteed — names the columns once for the whole file. JSON records instead carry their keys with them, so every object is self-describing, and an object may hold an array of objects holding arrays. That asymmetry decides the format choice more than any feature list does.

AspectJSONCSV
ShapeTree — objects and arrays nest freelyOne flat table of rows and columns
TypesSix types, declared in the syntaxNone — every cell is text
KeysEvery object carries its ownOne header row, by convention
NestingUnlimited depthImpossible without flattening or extra files
StandardRFC 8259, one grammarRFC 4180, plus persistent real-world dialects
Empty valuesnull, declared deliberatelyEmpty cell — or an entire missing column

Types and quoting: declared versus inferred

In JSON, a value's type is visible: quotes mean string, bare digits mean number, and true, false and null are exact tokens. In CSV, the file asserts nothing — 007 and 7 are both plain cell text, and every consumer re-infers types under its own rules. RFC 4180 does specify quoting precisely: fields containing commas, double quotes or line breaks are wrapped in double quotes, and embedded quotes are doubled. Files that skip this produce the classic broken-row bugs every data engineer has debugged.

The re-inference step is where data quietly corrupts. A ZIP code 02134 becomes the number 2134; 1.20 becomes 1.2; a long account number becomes 4.2E+12. JSON has the mirror-image rule — numbers cannot carry leading zeros at all, so a ZIP code must be a string there too — but at least the declaration is explicit rather than a guess made by someone else's spreadsheet.

Excel, bulk data and where each format wins

Excel behaviour deserves its own paragraph because it burns so many pipelines. Excel opens CSV natively but re-types every cell using the machine's locale: leading zeros vanish, ISO timestamps mangle into locale dates, and in much of Europe the semicolon dialect rules because the comma is a decimal separator. Saving then re-writes the file with those inferences baked in permanently. JSON never passes through Excel, which alone is a reason integrations prefer it.

At scale, CSV's flatness is a feature: rows parse one at a time with constant memory, which is why multi-gigabyte exports and column-oriented tools still speak CSV first. JSON wins wherever the consumer is a program and the structure is real: API payloads, configuration, nested documents. Choosing by consumer rather than by fashion resolves most arguments in one sentence.

When to pick which — and how conversion behaves

Pick CSV when the destination is tabular: spreadsheets, database bulk loads, BI and data-science tools. Pick JSON when the structure nests or the consumer is code. The guidance reverses constantly in real pipelines: an API returns JSON, an analyst wants CSV, a vendor sends CSV that a service must ingest — conversion is routine maintenance, not a migration project.

Conversion has honest limits. JSON-to-CSV must flatten: an array of objects becomes rows, the union of their keys becomes columns, and any nested array or object has to be stringified, joined or dropped. CSV-to-JSON must infer: empty cells become null or empty strings, and numeric-looking cells become numbers. This site's converters document those exact rules instead of guessing silently.

Frequently asked questions

Can CSV hold nested data like JSON?

No — RFC 4180 has no concept of nesting; a cell is a cell. The workarounds are flattening (address_city as a column name), serialising a JSON fragment inside a quoted cell, or splitting into multiple files joined by a key. JSON Lines — one flat JSON object per line — is the common middle ground for record-shaped data.

Why does Excel change my values when I open a CSV?

Excel re-infers a type for every cell as it loads: 02134 loses its leading zero, a sixteen-digit account number becomes 1.23457E+12, and 2026-09-19 becomes a locale-dependent date. Those inferences are saved back into the file. Importing through Excel's text-import wizard with columns forced to text avoids the damage; JSON, parsed by a program, never re-types anything.

Do the JSON and CSV converters upload my files?

No. Parsing, flattening and quoting all happen inside your browser tab; there is no upload endpoint, and the site's Content-Security-Policy allows network requests only to itself. Watching the DevTools Network panel while converting confirms it — nothing leaves the tab, which is the point of tools that run locally.

Is CSV an actual standard?

Core CSV is RFC 4180: CRLF line endings, comma delimiters, quote-doubling for embedded quotes, and an optional header row the standard explicitly notes is common. Real-world dialects persist anyway — semicolon delimiters in much of Europe, tab-separated variants, inconsistent encodings with or without a BOM. JSON's one-page grammar leaves far less room for dialects.

Which format handles very large files better?

CSV, usually. Rows can be parsed and discarded one at a time with constant memory, so file size barely burdens a streaming reader. JSON is typically parsed as a whole document before use, costing memory proportional to size — streaming JSON parsers exist but are not the default. For huge flat exports, stay in CSV; for huge nested ones, consider JSON Lines.

How does JSON-to-CSV conversion choose the columns?

By scanning the records and taking the union of keys, in first-seen order, as the header row; records missing a key get an empty cell. Nested objects and arrays cannot sit in a column, so converters must stringify or join them — this site's converter documents the choice it makes rather than leaving it to surprise.