JSON vs CSV vs YAML: Which Format Should You Use?
A practical comparison of three common data formats and how to convert between them safely.
If you work with data you will meet all three formats sooner or later. They are not rivals so much as tools for different jobs.
CSV: flat and simple
CSV is a table in plain text. It opens in Excel, imports into databases and is easy to produce. Its weakness is structure. It cannot hold nested data without awkward tricks, and it does not say whether "007" is a number or text. Use CSV to JSON when you need to feed spreadsheet data into an app.
JSON: the language of APIs
JSON handles nesting, lists, numbers, booleans and null. Almost every API speaks it. It is a bit noisy for humans to write, and it does not allow comments. If an API response arrives as one unreadable line, paste it into the JSON formatter to see the structure. Going the other way, JSON to CSV flattens an array of objects into rows for a spreadsheet.
YAML: friendly configuration
YAML is easier to read and allows comments, so it is popular for config files in Docker, Kubernetes and CI tools. Its downside is that indentation matters and a stray space can change the meaning. When you need to check a config as data, use YAML to JSON.
Rule of thumb
- Humans write it, machines read it: YAML.
- Machines talk to machines: JSON.
- A spreadsheet is involved: CSV.