JSON vs YAML vs XML vs CSV: Choosing a Data Format
Developer · Published October 10, 2026 · Updated October 24, 2026 · 3 min read
Written by Akinrinmade Michael
All four formats store structured data as text. They differ in how much structure they support, how easy they are to read, and where people expect to find them. Picking the wrong one rarely breaks anything, but it adds friction every time someone touches the file.
The same data, four ways
JSON
{"name": "Ada", "roles": ["admin", "dev"], "active": true}
YAML
name: Ada
roles:
- admin
- dev
active: true
XML
<user active="true"><name>Ada</name><roles><role>admin</role><role>dev</role></roles></user>
CSV (one row per role)
name,role,active
Ada,admin,true
Ada,dev,trueNotice that the CSV had to repeat Ada on two rows, because CSV can't hold a list inside one cell without inventing a convention. That's the clearest sign of what each format is good for.
JSON
The default for web APIs. It handles objects, lists, numbers, strings, true, false and null. It's strict, so mistakes are caught early, but it has no comments. Use the JSON Formatter to tidy and validate it. Every language can read it.
YAML
Readable by humans, because it uses indentation instead of brackets, and it allows comments. That makes it popular for configuration files such as Docker Compose, GitHub Actions and Kubernetes. The catch: indentation mistakes silently change the meaning, and a few values like no or on can be read as booleans by older parsers. Convert between the two with the YAML to JSON Converter.
XML
Older and more verbose, but good for documents with mixed text and markup, and still required by many enterprise systems, feeds and office file formats. It supports attributes and namespaces, which JSON doesn't. The XML to JSON Converter helps when you have to bridge the two.
CSV
Rows and columns, nothing more. It opens in any spreadsheet and is small and simple, which is why exports and imports use it. It can't hold nested data, and it has no types, so everything is text. Quoting rules vary, so a comma inside a value needs care, and spreadsheets in some countries use semicolons. The CSV to JSON Converter turns rows into objects and back.
Comparing them
| JSON | YAML | XML | CSV | |
|---|---|---|---|---|
| Nested data | Yes | Yes | Yes | No |
| Comments | No | Yes | Yes | No |
| Data types | Strings, numbers, booleans, null | Same, with extras | Everything is text unless a schema says otherwise | Everything is text |
| Human readable | Good | Best | Fair | Good for tables |
| Size | Small | Small | Largest | Smallest for flat data |
| Typical home | APIs, web apps | Config files | Documents, enterprise, feeds | Spreadsheets, exports |
| Easy to get wrong | Trailing commas | Indentation | Unclosed tags | Commas in values |
Validation and safety
- JSON and XML both have schema languages that can check a document's structure. JSON Schema is the common choice for JSON, and the JSON Schema Generator can start one from a sample.
- YAML can run into trouble if a parser is set to construct arbitrary objects. Use a safe loader for files you didn't write.
- CSV files from spreadsheets can contain formulas, so treat a CSV from an unknown source with caution before opening it in a spreadsheet.
A quick guide
- Sending data between a browser and a server? JSON.
- Writing a config file people will edit by hand? YAML, or JSON if you want strictness.
- Working with an older system or a document format? XML.
- Moving a table in or out of a spreadsheet? CSV.
Converting later
Don't agonize over the choice. Converting between these formats is easy when the data is simple, and awkward only when it isn't. Going from JSON to YAML or back loses nothing but comments. Going from JSON or XML to CSV works for flat lists and gets messy for nested data. Going from CSV to the others adds structure you have to decide on, such as which column is the key. Keep a sample file in both forms while you migrate, and compare the results.
If you aren't sure, JSON is the safest choice because every language can read it. You can always convert later, and the converters on this site keep the structure when they can.