ToolForge
ComparisonJSON

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.

Written by toolforge.websitePublished Last reviewed How we build and check these tools

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

JSONYAML
Structure fromBraces and bracketsIndentation
CommentsNoYes
Quotes requiredAlways, for keys and stringsRarely
Trailing commasSyntax errorNo commas to trail
Multi-line strings\n escapes onlyBlock scalars
ReferencesNoAnchors and aliases
Multiple documents per fileNoYes, separated by ---
Data types6More, including dates and explicit tags
Specification lengthA few pagesTens of pages
Parse ambiguityNoneSeveral well-known traps
Typical useAPIs, storageConfiguration, pipelines
In the browserNativeNeeds 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 Converter

Frequently 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.

Popular

JSON Formatter

Format, validate, and beautify JSON online

Open Tool

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

Open Tool

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

Open Tool

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

Open Tool

A quick check that the JSON your YAML produced is well-formed before it goes anywhere.

Sources

  1. 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

  2. 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

toolforge.website

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.

How we research and check this content · About ToolForge

Part of

JSON

What 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
Buy Me a Coffee