Comparing JSON, YAML, and TOML
Modern software development relies on structured text formats for configurations, API payloads, and package manifests. Choosing the right format depends on tooling and readability needs:
- JSON: Ubiquitous across web APIs and web services. Strict syntax with braces and double quotes ensures fast, deterministic serialization across languages.
- YAML: Optimized for human readability with whitespace hierarchy and minimal punctuation. Widely used in Kubernetes, GitHub Actions, and Ansible playbooks.
- TOML: Designed for clear configuration semantics without whitespace pitfalls. Popularized by Cargo (Rust), Poetry (Python), and Hugo.
Key conversion differences
Converting between formats involves important structural rules:
- Tabs versus spaces: YAML strictly prohibits tab characters for indentation. When converting from JSON with tabs to YAML, tabs are converted to two-space indentation.
-
Null values in TOML: TOML does not support
null. When converting JSON or YAML containing null properties, this tool offers an option to omit them with a warning. - Root structures: TOML documents must be tables (key-value maps) at the root. Top-level arrays or scalar primitives cannot convert directly to TOML without wrapping.
Worked examples
- Kubernetes manifests: Converting JSON deployment specs into clean, human-readable YAML with sorted keys for clear pull request diffs.
-
Cargo to JSON: Converting
Cargo.tomlinto JSON for automated dependency auditing scripts. -
npm package configs: Transforming
package.jsoninto YAML for documentation tables.
Common mistakes
- Indenting YAML with tabs: YAML parsers throw syntax errors on tabs. Always use spaces.
-
Unquoted boolean strings: In YAML 1.1, unquoted values like
yes,no,on, andoffare parsed as booleans rather than strings. - Duplicate dictionary keys: Having duplicate keys can lead to silent overwrites in downstream services.
Frequently asked questions
Why does YAML disallow tab indentation?
The YAML specification strictly forbids tab characters for indentation because different text editors render tab stops with varying column widths, which would break YAML indentation-based hierarchy.
Why does TOML require an object at the root level?
The TOML specification defines documents as top-level key-value tables. Top-level arrays or primitive strings cannot be expressed in TOML without wrapping them in an outer table object.
Are comments preserved during format conversion?
No. JSON has no native specification for comments, so comments in YAML or TOML cannot be represented when converting through an intermediate parsed data structure.
How are duplicate keys handled?
JSON parsers keep only the last occurrence of a duplicated key. This tool flags duplicate keys with line numbers in a warning banner so you can inspect shadowed values.
Is my data uploaded to any external server?
No. The converter runs 100% in your browser using client-side JavaScript libraries. Your configuration files, credentials, and payloads never leave your computer.