JSON to YAML / YAML to JSON
Convert JSON to YAML or YAML to JSON. Conversion uses js-yaml, a complete YAML 1.2 parser, so nested lists of objects, anchors and merge keys (<<: *defaults), block strings and multi-document files convert correctly, and invalid input is reported with its line and column. Strings that YAML would read as another type, such as "no" or "1.10", are quoted in the output. Conversion runs in your browser.
How to use the JSON to YAML
- Pick a direction with the JSON → YAML or YAML → JSON tab.
- Paste your input and press Convert. Errors appear in the output box with a line and column; a key that appears twice in the same mapping, for instance, is reported as a
duplicated mapping keyon the line where it repeats. - Copy the result.
For example, the JSON {"country":"no","version":"1.10","port":8080,"enabled":true,"tags":["a","b"],"db":{"host":"localhost"}} becomes:
country: 'no'
version: '1.10'
port: 8080
enabled: true
tags:
- a
- b
db:
host: localhost
The quotes around 'no' and '1.10' are deliberate: without them, older YAML parsers read no as the boolean false, and every YAML parser reads 1.10 as the number 1.1. Multi-line strings are written as literal blocks (|-), and nesting uses two spaces.
YAML 1.2 vs YAML 1.1: why the same file can mean different things
YAML is a superset of JSON, so every JSON document is also valid YAML, but plain (unquoted) YAML values are typed by their spelling. That spelling table changed between versions. YAML 1.1 (2005) treats yes, no, on and off as booleans, numbers with a leading zero as octal, and 22:22 as a base-60 number. YAML 1.2 (2009) keeps only true/false as booleans and drops the other rules.
Parsers still differ: PyYAML and many older libraries follow 1.1, while js-yaml 4, used here, follows 1.2. So country: no converts to {"country": "no"} on this page, but PyYAML would load False. The safe habit is to quote any value that must stay a string, which is what the JSON → YAML direction does for you.
Some rules apply in every version. version: 1.10 is the number 1.1, so YAML → JSON gives "version": 1.1; quote version numbers. Indentation must use spaces; a tab in indentation is an error.
YAML features that JSON lacks are resolved during conversion:
- Anchors and merge keys are expanded. This input:
converts to adefaults: &d retries: 3 job: <<: *d name: buildjobobject with both"retries": 3and"name": "build". - Comments are dropped, because JSON has no comments.
- Dates such as
released: 2024-01-15become ISO strings:"2024-01-15T00:00:00.000Z". - Several documents separated by
---become a JSON array with one entry per document.
Common use cases
- Kubernetes, Docker Compose and CI files. Convert a manifest to JSON to inspect it with
jq, or turn a JSON snippet from documentation into YAML for a workflow file. - OpenAPI specs, which are commonly written in YAML and consumed by tools as JSON.
- Checking what a YAML file really contains. Converting to JSON shows the resolved types, merged anchors and the exact strings a 1.2 parser sees.
- Generating config from JSON produced by a script, with values quoted wherever YAML would otherwise change their type.
Frequently asked questions
Why does "no" stay a string here when my Python app reads it as False?
no is a string. PyYAML follows YAML 1.1, where no, yes, on and off are booleans. Quote such values so every parser agrees.Why did my version number change from 1.10 to 1.1?
1.10 is a number in every YAML version, and the number 1.10 equals 1.1. Write version: "1.10" to keep it as text.Are YAML comments kept?
What happens to a file with several YAML documents?
--- are converted to a JSON array with one element per document.