YAML to JSON Converter
Convert YAML to JSON online: paste YAML and get indented JSON. Anchors and aliases are resolved, and syntax errors are reported with the exact line and column.
What this YAML to JSON converter does
The converter loads your YAML with js-yaml 4, a YAML 1.2 parser, and prints the resulting data with JSON.stringify. Anchors, aliases and << merge keys are expanded, comments are removed, and each plain scalar is given the type YAML’s rules assign to it. When the YAML is invalid, the error shows the line and column, plus a snippet of the offending line.
Converting is often the quickest way to answer “what does this YAML actually mean?”. YAML infers types from how a value looks, while JSON spells every type out, so the JSON output shows exactly which values became numbers, booleans, null or strings.
How to use the converter
- Paste YAML into the YAML Input pane, or load a
.yaml/.ymlfile with File. URL fetches a file from a server that allows cross-origin requests, such as a raw file on GitHub. - Choose an Indent of 2 spaces or 4 spaces for the JSON.
- Click Convert. Errors start with
Invalid YAML:and include the position, e.g.bad indentation of a mapping entry (2:6)for line 2, column 6. - Copy the JSON, Download it as
converted.json, or Clear both panes.
Before converting, the output pane shows your YAML as a tree; after converting, Tree Viewer toggles between that tree and the JSON text. Clicking a node copies its path.
How YAML values become JSON types
These results come from running each value through this page:
| YAML value | JSON result | Note |
|---|---|---|
yes, no, on, NO | "yes", "no", "on", "NO" | YAML 1.2: only true/false are booleans. |
~ or null | null | An empty value also becomes null. |
3.10 | 3.1 | Version numbers lose trailing zeros; quote them. |
0755 / 0o755 | 755 / 493 | Only the 0o form is octal in YAML 1.2. |
0x1F, 1e3 | 31, 1000 | Hex and exponent forms are numbers. |
1_000 | "1_000" | Underscores are not allowed in YAML 1.2 numbers. |
2024-01-15 | "2024-01-15T00:00:00.000Z" | Dates become ISO timestamps in UTC. |
2024-01-15T10:30:00+02:00 | "2024-01-15T08:30:00.000Z" | The offset is converted to UTC. |
.inf, .nan | null | JSON has no infinity or NaN. |
Integers beyond 253 lose precision, just as in any JavaScript code. Keys keep their spelling, so the GitHub Actions trigger on: stays "on". For the stories behind these rules, see YAML pitfalls.
Example: anchors and merge keys
defaults: &defaults
adapter: postgres
host: localhost
development:
<<: *defaults
database: dev_db
converts to:
{
"defaults": {
"adapter": "postgres",
"host": "localhost"
},
"development": {
"adapter": "postgres",
"host": "localhost",
"database": "dev_db"
}
}
Block scalars are resolved too: | keeps line breaks and adds one final newline, > folds lines into spaces, |- removes the final newline and |+ keeps all trailing blank lines.
Common problems and fixes
| Error or symptom | Cause | Fix |
|---|---|---|
bad indentation of a mapping entry | A key is indented more or less than its siblings, or a value contains an unquoted : (e.g. title: Ada: the Book). | Align sibling keys; quote values that contain a colon followed by a space. |
tab characters must not be used in indentation | YAML forbids tabs for indentation. | Replace tabs with spaces, or re-indent in the YAML Formatter. |
duplicated mapping key | The same key appears twice in one mapping. | Remove or rename one of them; JSON objects need unique keys too. |
expected a single document in the stream, but found more | The file contains several documents separated by ---, as Kubernetes manifests often do. | Convert one document at a time. |
unknown tag | Custom tags such as CloudFormation’s !Ref or !Sub are not part of the standard schema. | Use the long form (Ref: MyBucket) or remove the tags before converting. |
Output is just null | The input contains only comments or a null value. | Check that you pasted the whole file. |
Frequently asked questions
Why did my version number 3.10 turn into 3.1?
An unquoted 3.10 is a floating-point number in YAML, and the trailing zero has no numeric meaning. Write "3.10" in the YAML to keep it as a string. The same applies to postcodes and IDs with leading zeros.
Why are yes and no strings rather than booleans?
js-yaml follows YAML 1.2, where only true and false are booleans. Parsers that implement YAML 1.1, such as PyYAML, read yes, no, on and off as booleans, so the same file can mean different things in different tools.
What happens to comments?
They are discarded. JSON has no comment syntax, and the parser does not keep comments in the data it returns. If the comments matter, keep the YAML file as the source of truth.
Can I convert a Docker Compose or Kubernetes file?
Yes, as long as it is a single document. A multi-document manifest must be split at each --- line and converted piece by piece.
Is my YAML uploaded?
No. Parsing happens in your browser with js-yaml, so configuration files containing hostnames or credentials are not sent anywhere. The library itself is loaded from the jsDelivr CDN, but your YAML is not sent with it.