The Ultimate Guide to Data Serialization: JSON, YAML, XML, and TOON
An in-depth look at how we format and transmit data across the web, comparing JSON, YAML, XML, CSV, and the new TOON format.
Data serialization is the process of converting complex data structures (like objects and arrays) into a format that can be stored or transmitted across a network. Over the decades, we've seen a massive evolution in how we structure this data.
1. CSV: The Legacy Flat File
Comma-Separated Values (CSV) is one of the oldest and simplest formats. It excels at representing tabular data, making it the universal language of spreadsheets and legacy database exports.
- Pros: Extremely lightweight; easily read by Excel and data analysis tools.
- Cons: Cannot naturally represent nested or hierarchical data.
2. XML: The Enterprise Standard
eXtensible Markup Language (XML) dominated the early web and enterprise SOAP APIs. It uses verbose tags to define data structures.
- Pros: Highly structured; supports complex schemas and namespaces.
- Cons: Extremely verbose; slow to parse; terrible human readability for large files.
Tip: If you're forced to work with legacy XML APIs, use our XML to CSV converter to make the data manageable.
3. JSON: The Undisputed King of the Web
JavaScript Object Notation (JSON) took over the web due to its native compatibility with JavaScript and its perfect balance of human-readability and machine-parseability. It powers 99% of modern REST and GraphQL APIs.
- Pros: Lightweight, universally supported, easy to read.
- Cons: Does not support comments; strict syntax (no trailing commas).
4. YAML: The DevOps Darling
YAML Ain't Markup Language is the standard for configuration files (Docker, Kubernetes, GitHub Actions). It relies on indentation rather than braces, making it incredibly easy for humans to write.
- Pros: Supports comments; minimal syntax overhead; very readable.
- Cons: The whitespace dependency can cause infuriating parsing errors.
5. TOON: The High-Performance Challenger
Token-Oriented Object Notation (TOON) is a newer format designed to drastically reduce the payload size of repetitive arrays of objects (which JSON struggles with). By defining the keys once in a header and using delimited values for the rows, TOON achieves massive compression without losing structural integrity.
Explore the size differences yourself with our JSON to TOON converter.
Which Should You Use?
For almost all web APIs, stick to JSON. If you are writing configuration files intended for humans to edit, use YAML. If you are transferring massive datasets of uniform objects and need to save bandwidth, consider exploring TOON or compressing your JSON. And if you're dealing with accountants, you'll inevitably need CSV.
Part of the ThenCatch blog. Learn more about us or browse more guides.