# JSON, XML and CSV

> Three plain text ways to write down data. How JSON uses names and values, how XML uses tags, and how CSV holds a table, with the rules each one breaks on.

**Course:** [JSON, YAML and File Formats](https://learn.benibix.com/learn/development-formats)  
**Time:** 13 min

**After this lesson you can:**

- Read and write a small JSON file
- Spot the same data in XML and CSV
- Pick the format that fits the data

## How JSON, XML and CSV write the same data

JSON, XML and CSV are three plain text formats for data. JSON writes names and values in curly brackets, like "age": 36. XML wraps each value in tags, like <age>36</age>. CSV is a table, one row per line, with commas between the columns. Most web services send data as JSON, and its rules fit on one page.

JSON can hold text, numbers, true or false, null, lists in square brackets and groups in curly brackets. Groups can sit inside groups. Text must be in double quotes, and the names too. Almost every language can read and write it.

JSON is strict, and two slips break most files. A comma after the last item is not allowed. Comments are not allowed either. One stray comma, and the whole file fails to load, not just that line.

XML came first, in 1998. Each value sits between an opening tag and a closing tag, so every name is written twice. That makes it longer than JSON. It is still inside office files, news feeds, Android screens and many older business systems.

XML is strict too. A missing closing tag makes the whole file unreadable. HTML looks a lot like XML, with tags in angle brackets. The difference is that HTML is for pages people see, and XML is for data.

CSV is the simplest of the three. The first line usually names the columns, and every line after it is one row. Every spreadsheet app opens it. The catch is that CSV has no types, so a number and a word look the same.

A value with a comma in it breaks a CSV row into too many columns. Put that value in double quotes to keep it whole. Pick CSV for flat tables, JSON for nested data, and XML when a system asks for it.

## JSON, XML and CSV side by side

| Format | Looks like | Best for | Breaks on |
| --- | --- | --- | --- |
| JSON | Names and values in { } | Nested data, web services | A comma after the last item |
| XML | Values between tags | Office files, older systems | A missing closing tag |
| CSV | Rows of values split by commas | Flat tables, spreadsheets | A comma inside a value with no quotes |

## Which one to pick

1. **JSON.** When the data has groups inside groups, or a web service will read it.
2. **XML.** When the system on the other side asks for XML. Few new projects pick it.
3. **CSV.** When the data is one flat table that a person may open in a spreadsheet.

```json
{
  "name": "Emma",
  "age": 36,
  "admin": true,
  "skills": ["Python", "Git"]
}
```
Text in double quotes, a number, a true value and a list. No comma after the last item.

![Three panels show one record, Emma aged 36. JSON, lit up, writes it as name Emma and age 36 inside curly brackets. XML writes it with tags: a person tag holding a name tag and an age tag, each one opened and closed. CSV writes a table with a header line name,age, then the rows Emma,36 and Jack,29. A note says all three are plain text, and each fits a different shape of data.](https://learn.benibix.com/diagrams/dev-data-formats.svg)

### Example: Emma's file will not load

Emma adds a fifth setting to a JSON file of 30 lines, and the app stops starting. The error says unexpected character at line 31.

Line 30 is the last item, and it ends with a comma left over from a copy. She deletes the 1 comma, and the app starts.

**Words in this lesson:** [JavaScript Object Notation (JSON)](https://learn.benibix.com/term/development/json), [Extensible Markup Language (XML)](https://learn.benibix.com/term/development/xml), [Comma-Separated Values (CSV)](https://learn.benibix.com/term/development/csv)

> **The one thing to remember.** CSV is for flat tables, JSON is for nested data, and XML is for systems that ask for it. JSON breaks on one stray comma.

**Question:** Why does this JSON fail to load: {"a": 1, "b": 2,}

**Answer:** There is a comma after the last item. JSON only puts commas between items. A comma just before the last bracket breaks the whole file.

---

Source: https://learn.benibix.com/learn/development-formats/json-xml-and-csv
Author: Behnia Zarei (a developer in Vienna, Austria, who builds and teaches data, AI and business intelligence at BENIBIX)
Publisher: BENIBIX Learn (https://learn.benibix.com/)
Last updated: 2026-11-19
Licence: CC BY 4.0 (https://creativecommons.org/licenses/by/4.0/). Quote freely with attribution.
