Convert JSON to YAML

Paste JSON and get YAML. Errors show the line and column. Nothing leaves your browser.

JSON is what an API returns, and YAML is what many tools expect as a config file: Kubernetes manifests, GitHub Actions workflows, Docker Compose files and OpenAPI specs are all written in it. This page opens in the JSON to YAML direction with a short sample already converted. Objects become indented keys, lists become lines that start with a dash, and null stays null. Text that holds a line break becomes a block with a pipe so it stays readable. Strings that could be mistaken for another type, such as the text true or 123, are put in quotes, so reading the YAML back gives the same values. If the JSON has a mistake, such as a comma after the last item, the page names the line and column instead of guessing. JSON has no comments, so there is nothing to carry over, and you can add your own comments to the YAML afterwards.

How it works

  1. Paste JSON or YAML
  2. Choose the direction and the indent
  3. Copy the converted text

What is kept and what is lost

Keys, values, lists and nesting convert in both directions, and key order is kept. Comments do not survive, because JSON has no comments: a # comment in YAML is dropped when you convert to JSON, and JSON never had any. In JSON to YAML, strings that look like another type are quoted so they stay strings, so the text true becomes 'true' with quotes, and a key such as n is quoted because some YAML readers take it for no. Text with line breaks becomes a block with a pipe. Choose 2 or 4 spaces for the indent in either direction.

How YAML is read

YAML is read as plain data using the YAML 1.2 core rules. Words such as yes, no and on stay text and are not turned into true or false. A date such as 2001-01-01 stays a string. A number written 0x1F is read as 31, and ~ or null is null. Numbers larger than 9,007,199,254,740,991 lose their last digits, as in any JavaScript program, and .nan or .inf become null because JSON cannot hold them. Anchors and aliases are expanded into copies. A merge key written << is not merged and comes out as an ordinary key named <<.

Several documents, tags and safety

A YAML text can hold several documents separated by a line of three dashes. When it does, the JSON is one list with one item per document, and a notice says how many there were. A single document is converted as it is. Custom tags such as !!js/function are refused with an error, and nothing in your text is ever run. An alias chain that would expand to millions of values is stopped before the JSON is written, and so is an alias that refers to itself.

Errors and limits

A problem is reported as Line 4, column 2 followed by a short reason, such as bad indentation of a mapping entry. The reason comes from the reader and never includes your text. JSON is checked by the same rules as the JSON formatter page: no comments, no trailing commas, double quotes only. Everything runs in this tab. The YAML code is a separate download that loads when the page opens. Up to 500,000 characters are handled, and above 100,000 the result follows your typing after a short pause.

Frequently asked questions

Will the YAML read back as the same data?

Yes for plain data. Strings that look like numbers, booleans or null are quoted, so the type stays the same when a YAML reader loads the file. Key order is kept.

What does the error with a line and column mean?

The JSON is not valid at that spot, for example a trailing comma or single quotes. The message says what to change. Fix it there and the YAML appears at once.

Can I choose the indent?

Yes, 2 or 4 spaces. Most Kubernetes and CI files use 2. YAML does not allow tabs for indentation, so there is no tab option on this page.

Are my YAML comments kept?

No. JSON has no way to hold a comment, so comments are dropped when you convert YAML to JSON. Converting back will not restore them. Keep your original YAML if the comments matter.

Why does yes stay as the word yes and not become true?

The page reads YAML 1.2, where only true and false are booleans. Older YAML 1.1 readers treat yes, no, on and off as booleans, which is a common source of surprises, so this page leaves them as text.

What happens with several YAML documents?

Documents separated by --- become one JSON list, one item per document, and a notice tells you how many there are. If you want only one of them, paste just that document.

Can a YAML file run code on this page?

No. Only plain data is read. Tags such as !!js/function, which some loaders use to build functions, are rejected with an error, and the text is never evaluated.

Why did a long number change?

JSON and JavaScript hold whole numbers exactly only up to 9,007,199,254,740,991. A number like 12345678901234567890 is rounded to 12345678901234567000. Keep very long IDs in quotes so they stay text.