JSON, CSV and XML are three of the most common ways to store and exchange data. You’ll meet them when exporting from an app, calling an API, importing into a spreadsheet or moving data between systems. They can often hold the same information, but each is built for a different job.
This guide explains the differences in plain terms, helps you choose, and shows how to convert between them.
The same data, three ways
Here’s a small list of customers in each format.
CSV (comma-separated values):
id,name,city
1,Ana,Lisbon
2,Ben,Toronto
JSON (JavaScript Object Notation):
[
{ "id": 1, "name": "Ana", "address": { "city": "Lisbon" } },
{ "id": 2, "name": "Ben", "address": { "city": "Toronto" } }
]
XML (Extensible Markup Language):
<customers>
<customer id="1">
<name>Ana</name>
<city>Lisbon</city>
</customer>
<customer id="2">
<name>Ben</name>
<city>Toronto</city>
</customer>
</customers>
CSV: flat tables
CSV is a table in plain text. The first line usually holds column names; each line after that is a row, with values separated by commas (or sometimes semicolons or tabs).
Good for:
- spreadsheets: Excel, Google Sheets and others open it directly,
- importing and exporting from databases, CRMs and accounting tools,
- large, simple datasets where every row has the same columns.
Weak spots:
- It’s flat. There’s no natural way to store a list inside a row, such as several phone numbers per customer.
- Everything is text. Nothing in the file says whether
007is a number or a code. - There’s no single strict standard, so separators, quoting and encodings vary between programs.
JSON: nested data for apps and APIs
JSON stores objects (named fields) and lists, which can be nested inside each other as deeply as needed. It’s the usual format for web APIs and app settings.
Good for:
- data with structure, such as a customer with an address and a list of orders,
- APIs and web apps, since almost every programming language reads it easily,
- keeping basic types: numbers, true/false, null and text are distinct.
Weak spots:
- It doesn’t open nicely in a spreadsheet without converting it first.
- It has no comments, and a single missing comma makes the whole file invalid.
XML: tagged documents
XML wraps data in opening and closing tags, and elements can also carry attributes (like id="1" above). It’s older than JSON and still widely used in feeds, office file formats, configuration files and many business and government data exchanges.
Good for:
- documents that mix text and structure,
- systems that use schemas to validate data strictly,
- integrations that already expect XML.
Weak spots:
- It’s more verbose, so files are bigger and harder to read.
- The difference between attributes and child elements adds complexity when converting to other formats.
Which one should you use?
| If you need to… | Use |
|---|---|
| Open or edit data in a spreadsheet | CSV (or Excel) |
| Send data to or from a web API | JSON |
| Store nested or hierarchical data | JSON |
| Feed a system that requires XML | XML |
| Share a simple list with non-technical people | CSV or Excel |
| Keep app or tool configuration readable | JSON or YAML |
In practice, the system on the other end usually decides. When you have a free choice: CSV for tables, JSON for anything nested.
How to convert between them
All of these converters run in your browser, so your data stays on your device. You can convert several files at once.
JSON to CSV
Use the JSON to CSV converter. It handles the common cases sensibly:
- It finds your rows. If the JSON is a list, each item becomes a row. If the list is wrapped inside an object, like
{"data": [...]}or{"results": [...]}, it finds the first list of records and uses that. - Nested fields become columns. With Flatten nested fields on (the default),
address.citybecomes its own column. Turn it off to keep nested objects as JSON text in one cell. - Lists inside a row stay together. Arrays, such as a list of tags, are kept as JSON text in a single cell.
- Choose the separator: comma, semicolon or tab.
CSV to JSON
The CSV to JSON converter turns each row into an object, using the first row as field names. Blank column names become column1, column2 and so on, and duplicate names get a number added so nothing is lost.
With Detect numbers & booleans on (the default), 42 becomes the number 42, true becomes true, and empty cells become null. Values with leading zeros, such as 007, stay as text, which protects ZIP codes and IDs. You can also choose the indent: 2 spaces, 4 spaces or minified.
XML to JSON
The XML to JSON converter checks that the XML is valid first and tells you the line and column of any error. In the result:
- attributes become fields starting with
@_, for example"@_id": "1", - when an element has both attributes and text, the text goes in a
#textfield.
JSON to XML
The JSON to XML converter does the reverse. If your JSON has a single top-level field holding an object, that field becomes the root element. Otherwise everything is wrapped in a <root> element, and items of a top-level list become <item> elements. Field names that aren’t valid in XML are adjusted so the file stays valid.
XML to CSV
There’s no one-step XML to CSV converter, but two steps get you there: convert XML to JSON, then convert that JSON to CSV. Repeated elements become rows and nested elements become dotted columns.
Spreadsheets and YAML
- CSV to Excel and Excel to CSV move between plain CSV and
.xlsx. When a workbook has several sheets, each sheet becomes its own CSV. - For configuration files, YAML to JSON and JSON to YAML convert between the two.
Common pitfalls
- Excel and leading zeros. When Excel opens a CSV, it may strip leading zeros (
02134becomes2134) and show long numbers like card or account numbers in scientific notation. Use Excel’s import options to mark those columns as text, or convert the CSV to Excel first. - Accented characters. CSV files made by these converters include a marker that tells Excel the text is UTF-8, so names like “José” display correctly.
- Invalid JSON. If the converter says the JSON isn’t valid, look near the line it mentions for a missing comma, quote or bracket. Trailing commas, which some editors allow, aren’t valid JSON.
- Commas inside values. A value like
Lisbon, Portugalmust be wrapped in quotes in a CSV. The converters handle this for you; hand-written CSVs sometimes don’t.
Pick the format that fits the job, convert when you need to, and check a few rows of the result before you rely on it.
