JSON vs YAML: What Is the Difference?
The relationship between these two is closer than any other pair of data formats, and it runs in one direction that people routinely get backwards: valid JSON is valid YAML, but almost no YAML is valid JSON.
That asymmetry explains most of what follows — why configuration migrated to YAML, why data interchange did not, and why converting between them is safe one way and full of small traps the other.
The same data in both
JSON:
{
"name": "Ada Lovelace",
"born": 1815,
"active": true,
"languages": ["English", "French"],
"address": { "city": "London" }
}
YAML:
# the same data, with room to explain itself
name: Ada Lovelace
born: 1815
active: true
languages:
- English
- French
address:
city: London
No braces, no brackets, no commas, no quotes around most strings, and a comment — which JSON has no way to express at all. Structure comes from indentation.
Then the part that catches people: the JSON above, pasted verbatim into a YAML parser, also parses correctly and produces the identical result. YAML's flow style is JSON's syntax. The specification is precise about how this came about — JSON was "almost a complete subset of YAML" by coincidence, and YAML 1.2's stated focus was making YAML a strict superset of it.
So a YAML parser reads your JSON. A JSON parser reads almost none of your YAML.
At a glance
| JSON | YAML | |
|---|---|---|
| Structure from | Braces and brackets | Indentation |
| Comments | No | Yes |
| Quotes required | Always, for keys and strings | Rarely |
| Trailing commas | Syntax error | No commas to trail |
| Multi-line strings | \n escapes only | Block scalars |
| References | No | Anchors and aliases |
| Multiple documents per file | No | Yes, separated by --- |
| Data types | 6 | More, including dates and explicit tags |
| Specification length | A few pages | Tens of pages |
| Parse ambiguity | None | Several well-known traps |
| Typical use | APIs, storage | Configuration, pipelines |
| In the browser | Native | Needs a library |
Why configuration chose YAML
Kubernetes manifests, Docker Compose files, GitHub Actions workflows, Ansible playbooks, OpenAPI documents. All YAML, and none of that is accidental.
Comments. The single biggest reason. A configuration file is read by humans far more often than it is written, and a config that cannot explain why a value is what it is will accumulate that knowledge somewhere worse — a wiki, or nobody's head. JSON's lack of comments makes it actively unsuitable for anything a person maintains, which is why package.json is full of fields whose purpose you have to look up.
Less punctuation to get wrong. No trailing-comma errors, no unclosed braces, no quotes around every key. For a hand-edited 200-line file, that removes an entire class of mistake.
Multi-line strings that are readable. A script embedded in a CI config, a certificate, a SQL query. In YAML a block scalar keeps the line breaks and the layout:
script: |
npm install
npm test
In JSON that is one string with \n escapes throughout, which is unreadable and unmaintainable.
Anchors and aliases. YAML can define a block once and reference it repeatedly, which is why large CI configurations are not entirely copy-paste.
None of those advantages apply to a machine talking to a machine, which is exactly why the split happened the way it did.
Why interchange stayed with JSON
The case for JSON in an API is not that it is nicer. It is that it is boring, and that the parse has exactly one outcome.
One reading. JSON's grammar is small enough that every conforming parser agrees on what a document means. YAML's is large enough that implementations vary, and the format has several documented ways to surprise you — see below.
Native everywhere. Every browser parses JSON without a library. YAML in a browser means shipping a parser, which is a real cost on a page.
Speed and simplicity. JSON parsers are among the most optimised code in any runtime. YAML parsing is meaningfully slower, which matters when a service does it a million times an hour rather than once at startup.
Whitespace does not travel well. YAML's structure lives in its indentation, and indentation is exactly what gets damaged by templating, string concatenation, log pipelines and anything that reflows text. A JSON payload survives being pushed through a queue as a single line; a YAML document does not.
Security surface. Some YAML loaders can instantiate arbitrary objects from tagged data, which has produced real remote-code-execution vulnerabilities. Loading untrusted YAML requires a safe loader deliberately; loading untrusted JSON is inert by construction, because the format cannot express behaviour.
The YAML traps worth knowing before you convert
YAML's convenience comes from inference — it decides what your unquoted value means — and inference is where it bites. The converter here uses a real YAML parser rather than a pattern match, so it reproduces the standard behaviour faithfully, including the awkward parts.
Unquoted values get typed for you. version: 1.0 is the number 1, not the string "1.0". port: "8080" is a string; port: 8080 is a number. Convert to JSON and the difference is suddenly visible and suddenly matters, because a consumer expecting a string gets a number.
The Norway problem. In YAML 1.1, the unquoted values yes, no, on, off, y and n were booleans. So a country list containing NO for Norway produced false. YAML 1.2 narrowed booleans to true and false, but many parsers still run 1.1 semantics for compatibility, so quoting anything that could be read as a boolean remains the safe habit.
Leading zeros can become octal. A value like 0755 may be interpreted as an octal number, which is deliberate for file permissions and disastrous for a zip code or an account number. Quote them.
Tabs are illegal. YAML forbids tab characters for indentation entirely. An editor configured to insert tabs produces a file that fails to parse, with an error that rarely says "tab".
Duplicate keys behave differently. JSON permits them and parsers usually keep the last; many YAML parsers reject the document outright. A JSON file that has quietly worked for years can fail on conversion for this reason.
The general rule that avoids nearly all of it: quote any string whose content could be mistaken for something else — versions, ports, country codes, zip codes, anything with leading zeros, and anything that looks like a date.
Converting between them
The converter runs both directions with a real parser, in your browser — which matters here more than for most formats, because the YAML you most want to convert is a deployment manifest or a CI config, and those routinely contain hostnames, bucket names and occasionally secrets.
YAML to JSON is the direction that needs care, because inference has already happened by the time you see the output. Check the types in the result: a version that became a number, a port that became a string, a country code that became false. Everything YAML has and JSON does not — comments, anchors, multiple documents, block-scalar layout — is gone in the output, because JSON cannot express any of it. Anchors are expanded before conversion, so a config that referenced one block five times becomes five copies.
JSON to YAML is safe. Every JSON document has a YAML equivalent, and the output indents with two spaces. The conversion is also useful in an unexpected way: it is the fastest way to make a large minified JSON document readable, since YAML has less punctuation to wade through.
A practical workflow for debugging a Kubernetes manifest that is behaving oddly: convert it to JSON, format it, and look at the types. Errors that were invisible in YAML — a quoted number, a null where you meant an empty string, a nesting level you miscounted — are obvious once the braces are explicit.
YAML ↔ JSON Converter
Bidirectional YAML and JSON conversion with error reporting. It runs in your browser, so the files never leave your machine, and there is nothing to install or sign up for.
Try the YAML ↔ JSON ConverterFrequently asked questions
Is YAML really a superset of JSON?
For practical purposes yes, and the YAML 1.2 specification states that as its aim: every valid JSON document should be valid YAML. There are a handful of edge cases around duplicate keys and unusual escapes where a YAML parser is stricter, so treat it as "almost always" rather than a guarantee.
Can I use comments in JSON if I convert from YAML?
No. Comments are dropped in conversion because JSON has nowhere to put them. Keep the YAML as the source of truth and generate the JSON, rather than converting once and losing the explanations permanently.
Which is better for a configuration file?
YAML, in most cases, because comments and multi-line strings matter for anything a human maintains. TOML is worth considering for flat configuration — it avoids YAML's type inference entirely. JSON is the right choice only when a machine writes and reads the file.
Why did my YAML value change type when I converted it?
It did not change — the type was decided when YAML parsed it, and the conversion only made it visible. Unquoted 1.0 was already a number and unquoted no may already have been a boolean. Quote the value in the YAML source to keep it a string.
Is YAML slower than JSON?
Yes, meaningfully. The grammar is far larger and the inference rules add work. It rarely matters for configuration parsed once at startup, and it matters a great deal for anything on a request path — which is part of why APIs use JSON.
The short version
Same data model, different priorities. Use YAML where humans edit the file and comments earn their keep, and quote anything that could be mistaken for a number, a boolean or a date. Use JSON where machines exchange the data and one unambiguous parse is worth more than convenience. When you convert YAML to JSON, read the types in the output before trusting it — the inference already happened, and the JSON is just the first place you can see it.
Tools that go with this
Each one is here for a specific reason rather than because it is in the same category.
JSON Formatter
Format, validate, and beautify JSON online
The other half of the workflow: convert YAML to JSON, then format the result to see its real structure.
JSON Diff Comparator
Compare two JSON files and find differences
Comparing two configs is far easier as JSON, where a structural diff ignores indentation and key order.
JSON Schema Visualizer
Visualize JSON Schema structure and validation
Shows the shape a converted config actually has, which is how you catch a value that parsed as the wrong type.
JSON Parse Tool
Parse JSON strings into JavaScript objects
A quick check that the JSON your YAML produced is well-formed before it goes anywhere.
Related articles
What Is JSON?
JSON is a text format for structured data, with six value types and a grammar you can read in an afternoon. What it is, where it came from, and where it bites.
JSON vs XML: Which Should You Use?
JSON is smaller and easier to parse; XML carries attributes, namespaces and real validation. Where each one wins, and why the choice is rarely close any more.
Why Your JSON Is Invalid — Every Error Explained
Match the parser error to its cause: unexpected token, unexpected end of input, bad control character, and the invisible BOM. With the fix for each.
How to Escape Strings in JSON
Escaping JSON is easy until there are layers. How to escape a string, how to nest JSON inside JSON, and how to get a payload through a shell intact.
How to Format JSON
Turn minified JSON into something readable, or the reverse. What formatting changes about your data, what it silently normalises, and when to minify.
How to Validate JSON
Validating JSON answers three different questions: is it well-formed, does it match a schema, and is the data right. How to check each, and where each stops.
JSON Syntax Reference
Every JSON syntax rule in one place: the six value types, the escape sequences, what numbers may contain, and the rules people think exist but do not.
Sources
- YAML Ain't Markup Language (YAML) version 1.2, revision 1.2.2
YAML Language Development Team · Official documentation · published 1 October 2021 · accessed 7 September 2026
Cited for: JSON being "almost a complete subset of YAML", and YAML 1.2's aim of being a strict superset of JSON
- RFC 8259 (STD 90) — The JavaScript Object Notation (JSON) Data Interchange Format
IETF · Standards organisation · published 1 December 2017 · accessed 7 September 2026
Cited for: JSON's value types and its lack of comments, references or multi-document support
About the author
Builder and maintainer, ToolForge
Started ToolForge in May 2026 and has built and maintained it since, writing every tool on the site and the documentation that goes with each one.
Part of
JSONWhat JSON is, the syntax rules that actually trip people up, why a parser rejected your file, and how JSON compares with XML and YAML.
Browse all developer tools