How to convert JSON to YAML
- Paste JSON or open a file; the YAML appears as you type. Choose 2 or 4 spaces of indentation.
- To go the other way, switch the direction to YAML → JSON and paste YAML.
- Copy the result or download it as a
.yamlor.jsonfile.
JSON vs YAML
| JSON | YAML | |
|---|---|---|
| Structure | braces {} and brackets [] | indentation and - list items |
| Strings | always in double quotes | quotes only when needed |
| Comments | not allowed | # comment |
| Multi-line text | \n escapes | literal blocks with | |
| Typical use | APIs and data exchange | configuration files |
YAML 1.2 is a superset of JSON, so a JSON document is already valid YAML. The converter writes the more readable block style instead.
Values that must be quoted in YAML
Some unquoted words change their type in YAML: yes, no, on and off are booleans in YAML 1.1 parsers, 007 and 1e3 are numbers, and null or ~ mean null. This is the famous “Norway problem”: the country code NO turns into false when it is not quoted. The converter quotes such strings automatically, so the YAML reads back as exactly the same data.
Supported YAML for YAML → JSON
The parser understands the YAML used in configuration files and APIs: block mappings and lists, plain, single- and double-quoted strings, | and > multi-line blocks, inline [ ] and { } collections, comments and the --- document marker. Anchors (&), aliases (*) and custom tags are reported as unsupported, with the line number. Only the first document of a multi-document file is converted.
Frequently asked questions
Is YAML a superset of JSON?
YAML 1.2 was designed as a superset of JSON, so virtually every JSON file is also valid YAML. The opposite is not true: YAML has comments, anchors and multi-line blocks that JSON lacks.
Are comments kept when converting YAML to JSON?
No. JSON has no comments, so they are dropped. Keys, values and their order are kept.
Why is my YAML rejected?
The usual causes are tabs used for indentation (YAML allows only spaces), items of the same list or mapping that do not start in the same column, and a missing space after a colon. The error message tells you the line.
How are YAML values typed in the JSON?
Following the YAML 1.2 core schema: true/false become booleans, null and ~ become null and plain numbers become JSON numbers, while words like yes stay strings. Quote codes such as "007" in your YAML to keep them as text.