All guides

JSON vs YAML vs CSV: Choosing a Data Format

4 min read

JSON, YAML and CSV all store structured data as plain text, but each suits a different job. Choosing well saves you from parsing bugs and unreadable files.

JSON: the language of APIs

JSON represents nested objects and arrays with strict, simple syntax. Every programming language can read and write it, which is why nearly all web APIs use it. Its strictness is also its main annoyance: a single trailing comma or missing quote makes the whole document invalid, and it has no comments.

Tip: when an API response or config won't parse, paste it into the JSON Formatter. It pretty-prints valid JSON and shows an error for invalid input.

YAML: configuration humans edit

YAML expresses the same structures as JSON using indentation instead of braces, and it allows comments. That makes it popular for configuration — Kubernetes manifests, Docker Compose, GitHub Actions. The catch is that indentation is meaningful: a misplaced space changes the structure, and unquoted values can be interpreted unexpectedly (for example, no may become false in older parsers).

CSV: tables and spreadsheets

CSV stores rows and columns, one record per line, and opens directly in Excel and Google Sheets. It's ideal for flat, tabular data and exports. It can't represent nesting, everything is text, and values containing commas, quotes or line breaks must be quoted correctly — a common source of broken imports.

Which should you use?

  • Sending data between programs or calling an API: JSON.
  • Configuration files that people edit by hand: YAML.
  • Tabular data for spreadsheets, reports or bulk imports: CSV.

Converting between them

JSON and YAML convert both ways without loss, apart from YAML comments, which JSON can't hold. CSV converts to JSON as an array of objects keyed by the header row; nested JSON doesn't fit CSV's flat rows. EasyToConvert's data tools run in your browser, so configuration and data containing secrets never leave your device. The CSV to JSON conversion is also available as a REST API for automation.