How to convert JSON to YAML
- Paste your JSON into JSON. If it isn't valid JSON, the status line shows the line and column where it breaks.
- Pick 2 or 4 spaces for Indent. The YAML updates as you type.
- Copy the result or download it as a .yaml file.
JSON and YAML compared
| JSON | YAML | |
|---|---|---|
| Structure | Braces and brackets | Indentation |
| Quotes around strings | Always | Only when needed |
| Comments | Not allowed | Lines starting with # |
| Typical use | APIs, package.json, data exchange | Kubernetes, Docker Compose, GitHub Actions, Ansible |
The data is the same in both. Keys keep their order and null stays null. Empty objects and arrays come out as {} and [].
Before you use the YAML
- Indentation is part of the syntax. Keep it consistent when you edit the file, and never use tabs: YAML only allows spaces.
- Add comments now if the file will be edited by others. JSON had nowhere to put them.
- Numbers too long to store exactly in JavaScript (beyond about 9 quadrillion) are written as quoted strings with all their digits, so they aren’t rounded. Unquote them if your tool needs a number.