How to Convert YAML to JSON (and Back) Without Surprises
YAML ⇄ JSONConvert YAML and JSON both ways. Free, no sign-up.YAML and JSON describe the same kinds of data (objects, lists, strings, numbers, true/false, null). YAML is easier to write by hand, which is why Docker Compose, Kubernetes, GitHub Actions and many apps use it. JSON is what most APIs and programs expect. Converting between them is common, and mostly painless.
Convert
- Open YAML to JSON.
- Paste your YAML. The JSON appears next to it as you type.
- Choose the indentation, then copy or download the result.
- Use the swap button to go the other way, from JSON to YAML.
Files are converted in your browser, so configuration with hostnames or secrets is not uploaded. Still, avoid pasting real passwords into any tool you don’t need to.
Example
service: invoices
port: 8080
debug: false
owners:
- ada
- grace
becomes
{
"service": "invoices",
"port": 8080,
"debug": false,
"owners": ["ada", "grace"]
}
(The converter puts each list item on its own line; it is shortened here.)
YAML traps to know
YAML guesses types from how values look. That is convenient until it guesses wrong. This converter follows YAML 1.2, the current version; some tools (PyYAML, older Ruby and Go libraries) still follow YAML 1.1 and guess even more:
| You write | You might expect | This converter gives | Older YAML 1.1 tools | Fix |
|---|---|---|---|---|
version: 1.10 |
“1.10” | the number 1.1 | the number 1.1 | version: "1.10" |
zip: 01234 |
“01234” | the number 1234 | a number, possibly octal (668) | zip: "01234" |
country: NO (Norway) |
“NO” | “NO” | false | country: "NO" |
time: 12:30 |
“12:30” | “12:30” | the number 750 (12 × 60 + 30) | time: "12:30" |
Converting to JSON is a quick way to see what a YAML file really means. If a value in the JSON is not what you meant, put quotes around it in the YAML. Quoting is also the safest choice when the same file is read by several tools.
Other differences
- Comments (
# like this) exist in YAML but not in JSON, so they are dropped when converting to JSON. - Several documents in one YAML file (separated by
---) become a JSON array of documents. - Anchors and aliases (
&default,*default) are expanded, so repeated sections appear in full in the JSON. - Indentation is meaningful in YAML. Use spaces, never tabs.
Next steps
Check or tidy the JSON with the JSON Formatter, which also finds syntax errors with line and column. If your data is a table rather than a config file, CSV to JSON is the better fit.