Home / YAML tools / YAML to JSON

YAML to JSON Converter

Paste YAML and get JSON. Anchors and merge keys are resolved, several documents can be combined into an array, and errors are shown with their line number.

Options

Result

Convert YAML to JSON

Paste your YAML into the left box. The JSON is shown on the right as you type. Choose the indent, or minified output with no spaces, and copy the result or download it as a file.

# YAML
name: demo
ports: [80, 443]
debug: false

// JSON
{
  "name": "demo",
  "ports": [80, 443],
  "debug": false
}

How YAML values become JSON

In YAMLIn JSON
A mappingAn object
A sequenceAn array
true, falsetrue, false
null, ~ or an empty valuenull
Numbers such as 42 and 3.14Numbers
Text, quoted or plainStrings
A block scalar with | or >A string, with line breaks for |
An alias such as *nameA copy of the anchored value

Anchors and merge keys

YAML lets you define a value once with an anchor, such as &defaults, and reuse it with an alias, *defaults. JSON has no such feature, so the converter writes out the full value wherever an alias was used. With Resolve merge keys turned on, an entry written <<: *defaults is merged into its mapping, as it is by most tools.

Several documents

A YAML file can hold several documents separated by three dashes, and a JSON file holds only one value. With several documents, the result is an array with one item for each document. Tick Always return an array to get an array even for a single document.

What is lost or changed

  • Comments have no place in JSON and are dropped.
  • Very large numbers are rounded, because JSON numbers in JavaScript are limited to about 15 digits of exactness. The tool warns you.
  • Infinity and not-a-number values, written as .inf and .nan in YAML, cannot be written in JSON and become null.

Syntax errors in the YAML are shown with the line and column. To go the other way, use JSON to YAML. To check a file without converting it, use the YAML validator. For help with the language, see the YAML syntax guide.

Frequently asked questions

How do I convert YAML to JSON?

Paste the YAML into the box. The JSON appears at once. Copy it or download it as a file.

What happens to anchors and aliases?

The converter writes out the full value for every alias, because JSON has no way to reuse a value.

What happens to comments?

They are dropped. JSON does not support comments.

Can it convert a file with several documents?

Yes. The result is an array with one item for each document.