YAML to JSON

Paste YAML to turn it into JSON. It's also a YAML validator: a mistake is shown with its line and column, the line is highlighted, and the message says what to fix.

  • 100% free
  • Runs in your browser
  • No uploads
JSON layout
Several documents (---)

How to convert YAML to JSON

  1. Paste YAML or open a .yaml or .yml file. It converts as you type.
  2. Fix any error. The message names the line and column; Go to the error puts the cursor there.
  3. Choose the layout. 2 or 4 spaces for reading, Minified for one line.
  4. Copy or download the JSON. Download saves a .json file named after the file you opened.

Common YAML errors

  • Inconsistent indentation. Items at the same level must start in the same column. One space too few or too many changes which block a line belongs to, or makes the file unreadable.
  • Tabs. YAML doesn't allow tab characters for indentation. Replace them with spaces; most editors can do this for the whole file.
  • A colon inside a value. title: Note: read me is fine, but a value that starts with a special character such as *, &, !, { or [ needs quotes.
  • Duplicate keys. The same key twice in one mapping is an error here, because most programs would silently keep only one of the values.
  • Unclosed quotes or brackets. A quoted value or a [ list ] that isn't closed is reported where the file ends unexpectedly.

This YAML has a line indented by one space, which doesn't match either level around it:

server:
  host: example.com
  port: 8080
 timeout: 30
  retries: 3

The validator reports line 4 and explains that the indentation doesn't match the lines around it.

Example: Compose file with anchors

defaults: &defaults
  restart: unless-stopped
services:
  web:
    <<: *defaults
    image: nginx:1.27
    ports: ["80:80"]

converts to:

{
  "defaults": { "restart": "unless-stopped" },
  "services": {
    "web": { "restart": "unless-stopped", "image": "nginx:1.27", "ports": ["80:80"] }
  }
}

The merge key copies restart into web. Quoting "80:80" matters: in YAML 1.1, unquoted 80:80 can be read as a base-60 number.

How YAML values become JSON

Numbers (42, 3.5, 0x1F, 1e3) become JSON numbers, and integers longer than JavaScript can hold keep every digit. true and false become booleans; null, ~ and an empty value become null. Dates such as 2024-01-15 stay strings, since JSON has no date type. Block text with | keeps its line breaks; > joins lines with spaces.

Frequently asked questions

Can I use this as a YAML validator?

Yes. If the YAML can't be read, the JSON side shows the error instead, with the line and column and a plain explanation, and the line is highlighted in your YAML. If it converts, the YAML is valid. That doesn't check it against a schema, such as the keys Kubernetes expects, only that it's well-formed YAML.

Are anchors, aliases and << merge keys supported?

Yes. &name marks a block, *name repeats it, and <<: *name merges its keys into a mapping, as in Docker Compose and GitLab CI files. The JSON has the expanded values, since JSON has no references.

Why does yes stay a string?

This converter follows YAML 1.2, where only true and false are booleans. Older YAML 1.1 readers also treat yes, no, on and off as booleans, which famously turned the country code NO into false. If your tool uses YAML 1.1 and you mean a boolean, write true or false.

What happens to comments?

They're dropped, because JSON can't hold comments. Everything else (keys, values, order) is kept.

What about files with several documents?

A file with documents separated by --- (common for Kubernetes manifests) becomes a JSON array with one item per document. Choose First only to convert just the first document.