YAML to JSON

Convert YAML (incl. multi-document) into JSON.

The YAML to JSON converter parses YAML and shows the equivalent JSON, updating as you type. It can turn a file with several --- documents into a JSON array and reports the line and column of syntax errors. Use it to inspect configuration as plain data or to feed YAML into tools that only accept JSON.

What happens when YAML is converted to JSON?

YAML is a human-friendly data serialization language. A parser reads indentation, dashes and colons and builds a tree of mappings, sequences and scalars, which JSON can express with braces, brackets and quoted strings. Plain scalars are resolved by type: true and false become booleans, null and ~ become null, numeric text becomes a number, and other text stays a string. Features that JSON lacks are resolved or dropped. Comments are discarded, anchors and aliases are expanded into copies of the data, and timestamps such as 2024-01-05 are written as plain strings. A file with several documents separated by --- holds several values, which this tool can collect into one JSON array. This tool uses the yaml library with its default YAML 1.2 rules, so yes and no stay strings and the << merge key is not applied.

How to use YAML to JSON

  1. Paste YAML Enter the YAML text in the YAML pane.
  2. Pick the options Choose 2 spaces or 4 spaces for the Indent. If the text holds several documents separated by ---, tick Multiple documents (---) as JSON array.
  3. Read the JSON The JSON pane updates automatically. Check how numbers, booleans and null were typed.
  4. Fix any error If parsing fails, an error shows the line and column. Correct the indentation or quoting there.
  5. Copy or download Copy the JSON or download it as output.json.

Frequently asked questions

Why did my value become a number or boolean?

Unquoted plain scalars are resolved by type. Put the value in quotes to keep it as a string.

What happens to comments?

They are discarded, because JSON cannot hold comments.

How are anchors and aliases handled?

Aliases are replaced by a full copy of the anchored data. The << merge key is not applied by this tool and appears as a key called "<<".

What does the multiple documents option do?

It parses every document in the text and returns them as a JSON array. A trailing --- adds an empty document, which shows as null.

Are YAML 1.1 and 1.2 different here?

Yes. YAML 1.1 treated yes and no as booleans. The parser used here follows 1.2 by default, so they stay strings.

Is my data uploaded?

No. The conversion runs in the page and the text you enter is not sent anywhere.