CSV vs JSON vs XML: Which Data Format Should You Use?
The choice between CSV and JSON is really a choice about shape. If your data is a table, a flat format is the honest representation. If it has depth — objects inside objects, lists inside records — flattening it into columns costs you information, and a nested format keeps it.
CSV: the lowest common denominator that everyone reads
CSV is a table written as text: rows separated by line breaks, fields separated by a comma, quotes around anything containing a comma or a newline. That is the whole specification, and its ambiguity is both its strength and its weakness. It needs no library, it opens in any spreadsheet, and every language can parse it in a few lines.
What it cannot express is structure. A column holds one value per row. Nested objects, lists of things, mixed types and missing-versus-empty all have to be squeezed into a convention — a JSON blob in a cell, comma-separated values in one field, an empty string standing in for null. Each of those is a decision someone has to know about when reading the file back.
It also has encoding and delimiter traps. Files exported from Excel on Windows often arrive as CP-1252 rather than UTF-8, so accented characters turn into mojibake. European locales export with a semicolon instead of a comma. And a single unescaped quote can shift every subsequent row by one column.
JSON and XML: structure as a first-class citizen
JSON represents the same records as nested objects and arrays, so a list of tags is a list rather than a string someone split on commas. It is self-describing, handles missing values explicitly, and is the native dialect of web APIs. Its cost is verbosity — keys repeat in every record — and the fact that spreadsheets do not open it directly.
XML solves similar problems with a heavier tool: attributes, namespaces, schema validation and a mature ecosystem for documents that must be formally described. It dominates in enterprise interchange, publishing and formats like SVG, DOCX and SVG that are XML underneath. For an API in 2026, JSON is the default; for a contract that needs a published schema, XML still earns its keep.
- CSV
- Flat tables, human-readable, universal. Loses nesting and types.
- JSON
- Nested structures, APIs, configuration. Compact, typed-ish, everywhere.
- XML
- Validated, namespace-aware documents. Verbose, but formally specifiable.
- TSV
- CSV with a tab. Convenient when the data itself contains commas.
Converting between them without losing meaning
CSV to JSON is easy in one direction and lossy in the other. Going up, each row becomes an object keyed by the header — but every value arrives as a string unless you infer types, so a column of numbers becomes text and a column of dates becomes a pattern of characters. Going back down, something has to decide what a nested object becomes: a JSON blob in a cell, or flattened columns with dotted names.
Before converting, check four things: the encoding (UTF-8 with or without BOM), the delimiter, whether the first row is a header, and how missing values are written. Get those right and the round trip is faithful. Get them wrong and the conversion will succeed technically while quietly shifting columns.
For anything with real nesting, convert to JSON and keep it there. Flattening a nested structure into a spreadsheet is a one-way trip unless you preserve the original alongside the export.
Convert with these guides' formats
Frequently asked questions
When should I use JSON instead of CSV?
When your records have nested structures, lists per record, or mixed value types. If every row is genuinely a flat table, CSV is simpler and everything reads it.
Why did my numbers become text after converting CSV to JSON?
CSV has no types — every field is a sequence of characters. A converter must either keep values as strings or infer types from the text, and inference can get it wrong.
How do I stop accented characters breaking when I convert?
Make sure the source file is UTF-8. Files exported as CP-1252 or Latin-1 need to be re-encoded first, otherwise the converted output inherits the mojibake.
