JSON vs CSV vs XML
Updated 2026-09-20
CSV is a flat table: rows of values separated by commas, no types, no nesting, readable by every spreadsheet. XML (1998) is a tree of tagged elements with attributes, namespaces and schemas, verbose but rigorous, still the backbone of many enterprise, publishing and government exchanges. JSON (standardised 2013 as ECMA-404, RFC 8259) is a lighter tree of objects and arrays with native types, and it is what nearly every web API speaks.
They are not competitors so much as answers to different questions: CSV when the data is a table headed for a spreadsheet, JSON when a program will read it, XML when a schema, a signature or an existing standard requires it.
Side by side
| Criterion | JSON | CSV | XML |
|---|---|---|---|
| Structure | Nested objects and arrays | Flat rows and columns | Nested elements with attributes |
| Data types | String, number, boolean, null, object, array | Text only; types are guessed by the reader | Text; types via schema (XSD) |
| Schema / validation | JSON Schema (optional) | None | DTD, XSD, RELAX NG (mature) |
| Comments | No (JSON5 and JSONC variants add them) | No | Yes |
| Verbosity | Moderate | Minimal | High (opening and closing tags) |
| Size for the same table | About 2 to 3× CSV | Smallest | About 4 to 6× CSV |
| Human readability | Good | Good for small tables | Fair |
| Opens in Excel / Sheets directly | No (needs Power Query or import) | Yes | Partially (Excel XML import) |
| Typical use | Web APIs, config files, NoSQL documents | Spreadsheet exports, bulk data, logs | Documents, SOAP, RSS, Office files, e-invoicing (UBL) |
| Standard | ECMA-404, RFC 8259 | RFC 4180 (informal; dialects vary) | W3C XML 1.0 |
CSV: the table that opens anywhere
CSV wins whenever a human will open the data in a spreadsheet or a database will bulk-load it. It is the smallest of the three and the simplest to produce. Its weaknesses are exactly its simplicity: there is no way to say that "00123" is text and not the number 123, no way to nest an address inside a customer, and the format itself has dialects (comma versus semicolon in European locales, quoting rules, encodings) that break imports. Excel in a German or French locale, for example, expects semicolons.
When you receive JSON from an API and need it in Excel, flatten it to CSV: nested keys become columns like address.city. The JSON to CSV tool on this site does exactly that.
JSON: what programs exchange
JSON maps directly onto the data structures of every mainstream language, carries real types, and nests naturally, which is why REST APIs, configuration files and document databases converged on it. Parsing is built into browsers and every runtime. Its limits are the lack of comments and of a date type (dates travel as ISO 8601 strings), integers above 2^53 losing precision in JavaScript, and no standard schema unless you adopt JSON Schema.
XML: when the standard says so
XML is verbose and slower to parse, but it has what regulated exchanges need: strict schemas (XSD), namespaces to mix vocabularies, digital signatures (XMLDSig) and decades of tooling. Office documents (.docx, .xlsx), SVG, RSS, SOAP web services, Android layouts and the UBL e-invoices used by tax authorities (including Saudi ZATCA's e-invoicing) are all XML. You rarely choose XML for a new personal project; you use it because a counterpart or a standard requires it.
Which should I use?
- If you are…Exporting data for someone to open in Excel or Google SheetsChooseCSVOpens directly, smallest file, no tooling needed.
- If you are…Building or consuming a web API or a config fileChooseJSONNative types, nesting, and parsers built into every language and browser.
- If you are…Exchanging documents with a system that publishes an XSD schema (e-invoicing, SOAP, publishing)ChooseXMLValidation, namespaces and signatures the standard depends on.
- If you are…Storing settings that people will edit by hand and commentChooseXMLComments are allowed; alternatively use YAML or TOML rather than plain JSON.
- If you are…Bulk-loading millions of rows into a databaseChooseCSVStreams line by line and is the format every loader accepts.
Frequently asked questions
Can CSV hold nested data?
Not natively. The usual workaround is to flatten nested fields into dotted column names (customer.address.city) or to put a JSON string in a cell. For genuinely nested data use JSON.
Why does my CSV open in one column in Excel?
Your Excel locale expects a different separator (often a semicolon). Use Data, From Text/CSV and choose the delimiter, or save the file with the separator your locale uses.
Is JSON smaller than XML?
For the same data, JSON is typically half the size of XML because it has no closing tags and fewer structural characters. Both compress well with gzip, which narrows the gap on the wire.
Does JSON have a schema?
Optionally: JSON Schema is widely used for API validation and editor autocomplete, and OpenAPI descriptions are built on it. Unlike XSD it is not part of the JSON standard itself.
Which should I use for a configuration file?
JSON is fine when a program writes it. When humans edit it, formats that allow comments are friendlier: YAML, TOML, JSONC or XML.