YAML to JSON Converter
Paste YAML, get clean JSON. Runs entirely in your browser with the js-yaml parser. Handles anchors, multi-document files, and gives real error line numbers.
Your stuff stays yours. The conversion happens in this page's JavaScript. Nothing you paste here leaves your machine, and the tool keeps working with the network unplugged.
This converter uses the same js-yaml parser that Node.js projects use, so what validates here validates in your toolchain. It supports YAML 1.2, anchors and aliases, and multi-document streams (documents separated by --- come back as a JSON array). Parse errors report the offending line instead of failing silently.
How to use the YAML to JSON converter
- Paste your YAML into the YAML in box. This can be a single config file, a Kubernetes manifest, or several documents separated by
---lines. - Click Convert to JSON. The result appears in the JSON out box, indented with two spaces.
- If the parser rejects the input, the message under the buttons names the problem and gives its position as line and column, for example
(2:1). Fix that spot and convert again. - Click Copy result to put the JSON on your clipboard, or Clear to empty both boxes and start over.
What changes when YAML becomes JSON
JSON can only hold objects, arrays, strings, numbers, true, false, and null. YAML can express more than that, so a few things get flattened on the way through. Knowing which ones saves you from surprises later.
- Types are decided by the parser, not by you. An unquoted
3becomes a number and an unquotedtruebecomes a boolean. Quote a value in the YAML ("3") if you need it to stay a string. - Leading zeros are dropped. An unquoted
02134is read as the integer2134, andversion: 1.10becomes1.1. ZIP codes, version numbers, and IDs need quotes. - Dates become strings. An unquoted
2024-03-15is parsed as a timestamp and written to JSON as"2024-03-15T00:00:00.000Z", midnight UTC. - Special floats become null. YAML allows
.infand.nan, but JSON has no way to write them, so they come out asnull. So do~and a key with no value. - yes, no, on, and off stay strings. The parser follows YAML 1.2, where only
trueandfalseare booleans. Older YAML 1.1 tools treatnoas false, so the same file can mean different things in different programs. - Merge keys are expanded. A
<<: *defaultsline copies every key from the anchored mapping, and keys you write next to it override the copied ones. - Comments are gone. JSON has nowhere to put them.
A worked example
This input uses an anchor with a merge key, a date, a ZIP code without quotes, and a literal block string:
defaults: &defaults
image: nginx:1.27
replicas: 2
debug: no
web:
<<: *defaults
replicas: 3
ports:
- "8080:80"
released: 2024-03-15
zip: 02134
note: |
first line
second line
Clicking Convert to JSON produces:
{
"defaults": {
"image": "nginx:1.27",
"replicas": 2,
"debug": "no"
},
"web": {
"image": "nginx:1.27",
"replicas": 3,
"debug": "no",
"ports": [
"8080:80"
]
},
"released": "2024-03-15T00:00:00.000Z",
"zip": 2134,
"note": "first line\nsecond line\n"
}
Notice four things. The web object received image and debug from the anchor, but its own replicas: 3 won over the inherited value. The anchor source defaults is still in the output, because the converter keeps every key you wrote. The ZIP code lost its leading zero. And the | block kept its final line break as \n. Use |- instead if you do not want that trailing newline.
Common problems and how to fix them
"duplicated mapping key"
The same key appears twice in one mapping, often after a copy and paste. Some YAML tools silently keep the last value, but this parser stops and points at the second occurrence. Delete or rename one of them.
"bad indentation of a mapping entry"
This usually means an unquoted value contains a colon followed by a space, as in title: Error: bad. The parser reads the second : as the start of a new key. Wrap the value in quotes: title: "Error: bad". Colons without a following space, as in nginx:1.27 or a URL, are fine.
"unidentified alias"
An alias like *base refers to an anchor that does not exist yet. Anchors must be defined above the place they are used, and the names are case-sensitive. Check the spelling and move the anchored block higher in the file.
A list item quietly turned into one long string
If one item in a list is indented one space further than the item above it, YAML reads it as a continuation of the previous line. - a followed by - b gives ["a - b"] with no error. Line up every dash in a list at the same column.
An unexpected null at the end of the array
A trailing --- with nothing after it starts an empty document, which converts to null. A multi-document file then ends in , null ]. Remove the final separator. Along the same lines, input that contains only comments converts to plain null.
Related tasks
To go the other way, use the JSON to YAML converter. If you need to validate or minify the JSON you just produced, paste it into the JSON formatter. When you are comparing two versions of a config, the text diff checker shows exactly which lines changed.
Questions this tool gets asked
Is my YAML uploaded to a server?
No. The parser runs as JavaScript inside your browser tab. You can disconnect from the internet after the page loads and the tool still works.
How are YAML anchors and aliases handled?
Anchors (&) and aliases (*) are resolved during parsing, so the JSON output contains the expanded values, which is the standard behavior when converting YAML to JSON.
Can I convert a file with multiple YAML documents?
Yes. Documents separated by --- are parsed individually and returned as a JSON array, one element per document.
Why did my YAML fail to parse?
The most common causes are tabs used for indentation (YAML requires spaces) and unquoted strings containing special characters like colons. The error message reports the line number to check.