JSON to YAML Converter
Turn JSON into YAML and YAML back into JSON, and find out what is wrong when it will not.
Loading the converter…
Two ways of writing the same thing
JSON and YAML hold the same things: text, numbers, true and false, null, and lists and mappings of those. What differs is the punctuation. JSON marks structure with braces, brackets and commas; YAML marks it with indentation and dashes, which is why a Kubernetes manifest reads like a document and an API response reads like a machine wrote it. Converting between them is re-punctuation, not translation — which is precisely why the few things that do not survive the trip are worth naming.
Why this page asks the direction instead of guessing
Since YAML 1.2, every valid JSON document is also a valid YAML document — with one asymmetry worth knowing: a duplicate key such as {"a":1,"a":2} is resolved silently to its last value by JSON.parse, while the same key written twice in YAML is refused outright. That exception aside, then, a converter that detected what you had pasted would see JSON, correctly conclude "this is YAML", and hand it straight back. The direction is a choice here because the alternative is a tool that is wrong in one direction and cannot tell.
The three mistakes that break YAML
Almost every YAML file that will not parse fails for one of three reasons. A tab was used to indent a line, which YAML forbids outright — and which is invisible in most editors. A line is indented to a level that lines up with nothing above it. Or the same key appears twice in one block, which YAML does not allow. This page names which of the three it is and the line it is on; most converters print the parser's own words, which describe the parser's state rather than your mistake.
What the trip to JSON loses
Comments. JSON has nowhere to put them, so they are dropped, and this page says so under the result rather than letting you discover it in a code review. Anchors and aliases are expanded into the values they stand for, because JSON cannot refer to a value twice. And two things YAML can hold have no JSON spelling at all — .inf and .nan — so rather than write them as null, which is what the browser's own JSON.stringify does without a word, this page refuses and tells you which value it was.
Dates stay strings
Under YAML 1.2's core schema, 2001-12-14 is text unless something asks for it to be a date. Older tools built on YAML 1.1 turn it into a timestamp, and turn no into false and 012 into ten — the famous "Norway problem", where the country code NO becomes a boolean. This converter reads by 1.2, so NO and dates stay strings — though 012 becomes the number 12, as 1.2 says it should. And it writes YAML that a 1.1 reader cannot misread either: strings like "NO", "yes" and "2001-12-14" are quoted on the way out, so the file means the same thing to PyYAML as it does here.
If the JSON side is the problem
A document that will not convert because the JSON itself is broken gets the same treatment the JSON Formatter gives it: the line, the column, and what the mistake actually was — a trailing comma, a single quote, a stray Python True.
Nothing is uploaded
Your browser does the work. Nothing is sent anywhere, and the test suite for this page checks every request the converter makes and fails if one of them could carry the text. YAML files are configuration, and configuration is where the credentials live.
Questions
How do I convert JSON to YAML?
Paste the JSON into the box with "JSON to YAML" selected. The YAML appears as you type, with two-space indentation and the keys in the order you wrote them, except keys that are whole numbers, which JavaScript itself sorts ahead of the rest. Nothing is uploaded — the conversion happens in your browser.
Is YAML really a superset of JSON?
Since YAML 1.2, yes — with one asymmetry worth knowing: JSON tolerates the same key twice and keeps the last value, so a document like {"a":1,"a":2} converts here without complaint, while the identical pair of keys written in YAML is refused as a duplicate. Otherwise, every valid JSON document is also a valid YAML document, which is why this page asks you which direction you want rather than guessing — a document you paste to convert to YAML would parse perfectly well as YAML already, so detection would be wrong exactly when it mattered.
Why will my YAML not parse?
Overwhelmingly it is one of three things: a tab used for indentation, which YAML forbids outright; a line indented to a level that does not line up with anything above it; or the same key twice in one block. This page names which one it is and the line it is on, rather than printing the parser’s own description of its state.
What happens to my comments?
Going from YAML to JSON they are dropped, because JSON has nowhere to put them, and this page tells you when that has happened rather than letting you find out later. Going the other way there are none to lose.
What about dates, .nan and anchors?
A date like 2001-12-14 stays a string in both directions: YAML 1.2 does not guess at dates, and neither does this tool. Infinity and .nan are refused with an explanation rather than silently written as null, which is what JSON.stringify would do. Anchors and aliases are expanded, since JSON has no way to refer to a value twice.
Is what I paste sent anywhere?
No. Everything happens in your browser, and that matters here: YAML files are configuration files, and configuration files hold keys, tokens and connection strings.
Related WGX tools
- JSON Formatter
Make JSON readable, make it small, or find out exactly what is wrong with it.
- Base64 Encoder & Decoder
Turn text into Base64 and Base64 back into text.
- URL Encoder & Decoder
Make text safe to put in a URL, and read an encoded one back.