JSON Essentials · Ch. 3
Converting Between JSON, YAML, CSV, and XML: Choosing a Format and Avoiding the Pitfalls
WebTool Team · Published 2026-09-08 · JSON / YAML / CSV / XML / Data Formats
JSON suits API transport, YAML suits hand-written config, CSV suits flat tables, and XML lives on in traditional enterprise systems. The hard part of converting between them isn't syntax — it's types: CSV has none, YAML guesses them, and in XML everything is a string. This site offers JSON to YAML, JSON to CSV, and JSON to XML converters.
Comparing the four formats
| Dimension | JSON | YAML | CSV | XML |
|---|---|---|---|---|
| Primary use | APIs, config files | Human-maintained config | Tabular data exchange | Enterprise systems, documents |
| Data types | Six | Six + auto-inference | Strings only | Strings only |
| Nesting | Native | Native | Not supported | Native |
| Comments | ❌ | ✅ | ❌ | ✅ |
| Readability | Medium | High | High (pure tables) | Low |
Three frequent conversion pitfalls
1. JSON → CSV only works for flat arrays. CSV is a two-dimensional table: the JSON must be an array of objects with consistent keys. Nested objects get flattened (e.g. author.name) or serialized into strings — decide your column layout before converting.
2. YAML's type inference "helps" too much. version: 1.10 parses as the number 1.1; on/off/yes/no are booleans in YAML 1.1; a numeric-looking zip code like code: 010 becomes octal 8. When writing YAML values, add quotes whenever in doubt.
3. XML → JSON loses information. XML carries data in both attributes and text (<a x="1">text</a>), and allows repeated sibling elements. During conversion, attributes often become special keys like @x, and distinguishing a single element from a one-element array is error-prone. Conventions differ across tools, so always check the other side's conversion rules when integrating systems.
When not to use JSON
- Config that people edit by hand often → YAML or TOML (we have YAML and TOML tools).
- Data that Excel needs to open → CSV. Note that Excel opens UTF-8 CSVs with mojibake unless the file carries a BOM.
- Enterprise integrations requiring strict schema validation → XML/XSD is still the de facto standard.
Last updated: 2026-09-08