Comparison
JSON, YAML, XML and CSV
Converting between these is lossy in one direction far more often than people expect, and the loss is silent. The table is mostly about which capabilities exist on each side, because a capability the target does not have is data that quietly disappears.
Side by side
| JSON | YAML | XML | CSV | |
|---|---|---|---|---|
| Nesting | Yes | Yes | Yes | No — flat rows only |
| Comments | No | Yes | Yes | No |
| Types | Yes | Yes | With a schema | Everything is text |
| Whitespace matters | No | Yes, critically | No | No |
| Attributes | No | No | Yes | No |
| Opens in a spreadsheet | No | No | No | Yes |
The short answer
Anything nested flattens or breaks on the way to CSV, so that conversion is one-way unless the data was already a table. YAML holds everything JSON does plus comments, which means JSON to YAML is safe and YAML to JSON drops every comment. And a CSV that came from a spreadsheet often arrives with leading zeroes and long numbers already mangled by the spreadsheet, before any converter sees it.
In more detail
Nesting is what CSV cannot hold
A CSV is rows and columns, with no way to express a value that is itself a list or an object. Converting nested JSON to CSV therefore has to flatten, repeat or discard, and every tool chooses differently. If the data was already tabular the conversion is clean; if it was not, treat the result as a report rather than as the data.
Spreadsheets damage CSVs before any converter sees them
Opening a CSV in a spreadsheet and saving it again will commonly strip leading zeroes from identifiers, turn long numbers into scientific notation, and reinterpret anything that looks like a date. The file is damaged at that point, and no converter downstream can tell. Importing as text, rather than opening, avoids it.
YAML's indentation is its weak point
YAML holds everything JSON does and adds comments and anchors, which is why configuration files prefer it. The cost is that meaning depends on whitespace, so a single misplaced space changes the structure rather than producing an error. Converting to JSON and back is a reliable way to find out what a file actually says.