Home / YAML tools / JSON to YAML

JSON to YAML Converter

Paste JSON and get clean YAML. Choose the indent and the quoting, sort the keys, and protect values such as yes and no from being read as booleans.

Options

Result

Convert JSON to YAML

Paste your JSON into the left box and the YAML appears on the right. If the JSON has an error, you see the line and column, with an excerpt, so you can fix it.

// JSON
{"name": "demo", "ports": [80, 443], "env": {"MODE": "prod"}}

# YAML
name: demo
ports:
  - 80
  - 443
env:
  MODE: prod

Strings that need quotes

In JSON every string has quotes. In YAML most strings do not need them, but some would be read as something else if they were left bare. The converter adds quotes where they are needed:

  • Text that looks like a number, a boolean or null, such as "42", "true" or "null".
  • Text that contains a colon followed by a space, a hash sign after a space, or that starts with a character that has a special meaning, such as a dash, an asterisk or a bracket.
  • The key <<, which is the merge key in YAML.
  • Empty strings.

The yes and no problem

In YAML 1.2, the current version, yes and no are ordinary text. In YAML 1.1, which many older tools still follow, they are booleans, and so are on, off, y and n. Country lists and settings are often broken this way: the code NO for Norway becomes false. The option Quote values that older YAML 1.1 readers treat as booleans, which is on by default, adds quotes to those words, and to numbers with leading zeros such as 0755, so that every tool reads them as text.

Options

  • Indent: 2 or 4 spaces.
  • Indent list items under their key, wrap length and key sorting work as in the YAML formatter.
  • Quote all strings: writes every string in double quotes, which some teams prefer for configuration files.

Multi-line text

A string with line breaks is written as a block scalar, with the | sign, so that the text is easy to read and edit in the YAML file.

The conversion is checked on thousands of generated documents, and reading the YAML back always gives the original data. Nothing is uploaded. To convert the other way, use YAML to JSON, and for the rules of the language, read the YAML syntax guide.

Frequently asked questions

How do I convert JSON to YAML?

Paste the JSON into the box. The YAML appears at once and can be copied or downloaded.

Why are some strings quoted in the YAML?

Strings that would be read as a number, a boolean or null, or that contain special characters, need quotes to keep their meaning.

Why are yes and no in quotes?

Older YAML 1.1 parsers read them as booleans. The quotes make sure that every tool reads them as text. You can turn this off.

Is the conversion lossless?

Yes. Reading the YAML back gives the same data as the JSON.