YAML to JSON converter

Paste YAML to get JSON, or JSON to get YAML. Errors show the line and column. Kubernetes manifests, Docker Compose files and CI configs all work.

How to use the YAML to JSON converter

  1. Choose YAML → JSON or JSON → YAML.
  2. Paste your YAML or JSON into the input box, or click Load sample to see an example with an anchor and alias.
  3. Pick 2 spaces or 4 spaces for the output indentation.
  4. Check the status line: it says Valid YAML (and how many documents it found), or shows the first error with its line and column.
  5. Click Copy to copy the result.

YAML and JSON

YAML is a superset of JSON designed to be written by hand: indentation instead of braces, no quotes needed for most strings, and comments. JSON is stricter and is what most APIs and programs read. Converting YAML to JSON is a quick way to see exactly what a config file means, because every implicit type, anchor and merge is spelled out in the result.

Parsing uses the open-source yaml library with the YAML 1.2 core schema, running in your browser. Merge keys, which YAML 1.2 dropped but Docker Compose and CI files still use, are turned on.

Worked example: anchors, aliases and merge keys

An anchor (&defaults) names a value, an alias (*defaults) repeats it, and a merge key (<<) copies a mapping's keys into another mapping. Keys written next to the merge win:

defaults: &defaults
  image: node:20
  restart: always
services:
  web:
    <<: *defaults
    ports: ["8080:80"]
  worker:
    <<: *defaults
    restart: "no"

converts to:

{
  "defaults": { "image": "node:20", "restart": "always" },
  "services": {
    "web": { "image": "node:20", "restart": "always", "ports": ["8080:80"] },
    "worker": { "image": "node:20", "restart": "no" }
  }
}

The tool indents each key on its own line; it is condensed here. Note that "no" is quoted in the YAML. Docker Compose expects the string no for restart, and quoting keeps it a string in every YAML version.

Implicit types and the Norway problem

Unquoted values are typed by how they look, and the rules changed between YAML 1.1 and 1.2. In YAML 1.1, yes, no, on and off are booleans, so a list of country codes turns Norway's NO into false. This converter follows 1.2, but other tools you feed the same file to may not.

Unquoted YAMLJSON here (YAML 1.2)Older YAML 1.1 parsers
NO, yes, on"NO", "yes", "on"false, true, true
0755755493 (octal)
0o755493"0o755"
12:30"12:30"750 (base 60)
2024-01-15"2024-01-15"Often a date object
1.101.11.1
~ or nothingnullnull

The safe habit is to quote anything that must stay a string: version numbers, country codes, file modes, times and ZIP codes.

In the other direction, JSON → YAML writes YAML that older parsers read the same way: it puts quotes around strings such as "NO", "yes", "on" and "1.10" that would otherwise change type. Long strings are not wrapped onto several lines.

Things to watch for

Reading error messages

Errors give the line and column where the parser gave up, which is often just after the real mistake. A common one is "Nested mappings are not allowed in compact mappings", which usually means a key is indented under a line that already has a value, like key: value followed by an indented bad: 1. Another is an unclosed [ or { in a flow collection, reported on the following line.

Key terms

YAML
YAML Ain't Markup Language: a human-friendly data format that uses indentation for structure, allows comments and needs few quotes. Version 1.2 is a superset of JSON. It is widely used for Kubernetes, Docker Compose, CI pipelines and app configuration.
JSON
JavaScript Object Notation, a text format for structured data defined in RFC 8259. It has objects of key/value pairs, arrays, double-quoted strings, numbers, true, false and null. It is the most common format for web APIs and many configuration files.
Anchor
A YAML marker, written &name before a value, that labels that value so it can be reused later in the same document with an alias. Anchors let you define shared settings once.
Alias
A YAML reference, written *name, that repeats the value labeled by the matching anchor. When YAML is converted to JSON, each alias is replaced with a full copy of that value.
Merge key
The YAML key <<, which copies all the keys of an anchored mapping into the current mapping; keys written alongside it take priority. It comes from YAML 1.1 and is widely used in Docker Compose and CI files.
Multi-document stream
A single YAML file or input holding several documents separated by lines of three dashes (---). Kubernetes manifests often bundle several resources this way.
Norway problem
The YAML 1.1 behavior where unquoted no, yes, on and off are read as booleans, so the country code NO becomes false. YAML 1.2 treats them as strings; quoting such values avoids the issue in every version.
Block scalar
A multi-line YAML string introduced by | (literal), which keeps line breaks, or > (folded), which joins lines with spaces. Indentation marks where the string ends.

Frequently asked questions

How do I convert YAML to JSON?
Paste the YAML with YAML → JSON selected. The JSON appears as you type; copy it with one click.
Is it safe to paste a config with secrets?
The conversion runs in your browser and nothing is uploaded or stored. Even so, it is good practice to remove real secrets before pasting them anywhere.
Why did my version number change?
Unquoted 1.10 is read as a number and becomes 1.1. Put quotes around values that must stay text.
Does it support YAML 1.1 (yes/no booleans)?
It follows YAML 1.2, where yes and no are plain strings, as in most modern tools. Merge keys (<<), a YAML 1.1 feature, are still supported because Docker Compose and CI files rely on them.
What is the Norway problem in YAML?
In YAML 1.1, unquoted no, yes, on and off are booleans, so the country code NO (Norway) is read as false. YAML 1.2 fixed this, but many tools still use 1.1 rules. Quote short codes and words like these, for example country: "NO".
How do I validate a YAML file?
Paste it in with YAML → JSON selected. If it parses, the status line says Valid YAML; otherwise it shows the first error with its line and column, such as a tab in the indentation, a duplicate key or an unclosed bracket. It checks syntax, not whether the keys suit Kubernetes or another tool.
Why does my YAML file with --- turn into an array?
--- separates documents in one YAML stream, as in a Kubernetes file with several resources. Each document becomes one element of a JSON array, in order. A single document with no separator converts to a plain object.
Are YAML anchors and aliases kept in JSON?
No. JSON has no references, so each alias is replaced with a full copy of the anchored value, and merge keys are applied. The JSON can be much longer than the YAML, but it shows exactly what each section contains.