MiServe DevTools

Your lid

Pin tools here. They are saved in this browser.

JSON to YAML Converter

Convert JSON to YAML and YAML to JSON as you type: edit either side and the other one follows.

JSON indentation
YAML indentation

Runs in your browser. Nothing you paste is uploaded.

About this tool

How the two formats relate

JSON and YAML describe the same kind of data: mappings, lists, strings, numbers, booleans and null. YAML 1.2 was written so that JSON is a subset of it, and then adds what a hand-edited file needs: comments, indentation instead of brackets, multi-line strings, several documents in one file, and anchors with aliases to reuse a value.

Going from JSON to YAML keeps every value, with one exception: a key that appears twice in the same object keeps only its last value, because a YAML mapping cannot repeat a key. Going from YAML to JSON keeps the data only: comments disappear, aliases and << merge keys are replaced by the values they point to, custom tags such as !Ref are removed while their values stay, and keys that are not strings, such as 1 or true, become their text.

YAML pitfalls worth knowing

The Norway problem. In YAML 1.1 the unquoted words yes, no, on and off are booleans, so a list of country codes containing no ends up with false in it. YAML 1.2 keeps only true and false. The parser in this tool follows YAML 1.2 unless the document starts with a %YAML 1.1 directive, so it reads no as the string "no". Many parsers still in use apply the 1.1 rules, so when this tool writes YAML it puts such strings in quotes.

Version numbers. An unquoted 1.10 is a floating-point number, and as a number it is 1.1. Version numbers, postal codes and anything else that only looks like a number must be quoted to stay text: version: "1.10".

How this tool converts

The side you edited last is the source and the other side is rewritten from it. If the source does not parse, the error appears under it and the other side keeps the last valid conversion. The indentation options apply to the generated side; changing the JSON indentation also re-indents JSON that you typed, while YAML that you typed is never rewritten, because that would remove its comments.

Keys stay in the order of the source, including keys made of digits, which a JavaScript object would move to the front. Integers larger than 2 to the power of 53 are copied digit for digit in both directions. A YAML file with several documents separated by --- becomes a JSON array, and the page says so. A key that is used twice in one YAML mapping is reported as an error. YAML is read and written by the open-source yaml package, running in your browser.

Questions

Is every JSON document also valid YAML?

YAML 1.2 was designed so that JSON is a subset of it, and a YAML 1.2 parser reads a JSON document. A rare exception is an object that repeats a key, which YAML does not accept. You can try it here by pasting JSON into the YAML side.

What happens to YAML comments and anchors?

JSON has neither. Comments are dropped, and every alias is replaced by a copy of the value its anchor holds. Converting that JSON back gives YAML with the same data but without the comments and anchors.

Why did 1.10 become 1.1?

Without quotes, YAML reads 1.10 as a floating-point number, and the number is 1.1. Write it as "1.10" to keep it as text. The same applies to values such as 010 or 1e3.

Is my data sent to a server?

No. Both conversions run in JavaScript in your browser tab, and the tool makes no network request with what you type.

More in Data