JSON Tool 09

JSON to YAML (and back)

Convert JSON into YAML, or parse YAML back into JSON — anchors and aliases resolved, every document in a multi-document file kept, and errors reported with the line and column that caused them.

JSON Paste JSON to convert

Paste JSON to convert

Objects, arrays and nesting become YAML blocks
YAML Result appears here

YAML appears here

Text is quoted only where YAML would otherwise read it as another type
About JSON and YAML conversion

YAML is a superset of JSON written for humans: indentation instead of braces, comments, and anchors for repeated blocks. Converting between the two is not lossless in either direction, and this tool says what it changed rather than hiding it.

Converting YAML to JSON resolves anchors and aliases into the values they point at, keeps every document in a multi-document file, and drops comments — JSON has no comment syntax. Converting JSON to YAML cannot preserve key order semantics beyond what JSON already gives you, and numbers are held as JavaScript numbers in both directions, so an integer above 253 may come out different from what you typed. The tool warns when your input contains one.

Example JSON

{
  "name": "web",
  "replicas": 2,
  "debug": "true",
  "ports": [80, 443]
}

Generated YAML

name: web
replicas: 2
debug: 'true'
ports:
  - 80
  - 443

Frequently asked

Is my JSON or YAML uploaded?
No. Both directions run in the page against a bundled copy of js-yaml, and no request carries the document. There is also no share link to send a colleague, because there is no server copy to link to.
Why does a large number come out slightly different?
JavaScript numbers are floating point, so an integer above 2^53 - 1 (9007199254740991) may not survive the parse exactly and comes out rounded. The tool counts such literals in your input and warns in the status bar, but it does not repair them. If an ID has to keep every digit, quote it as a string in the source.
What happens to the comments in my YAML?
They are dropped. Comments are not part of the data a YAML file describes and JSON has no syntax for them, so only the values are converted.
What does a YAML file with several documents become?
A JSON array with one element per document, and the status bar states how many were merged. A single JSON text cannot hold separate documents, so the array is the closest faithful representation.
Are anchors and aliases preserved?
They are resolved into the values they point at. YAML to JSON expands an alias to its referenced value, and JSON to YAML does not invent anchors because JSON has no syntax for them. A YAML document that refers to itself through an anchor cannot be represented as JSON, and the tool says so instead of writing a broken file.