How to use the yaml and json converter
- Choose the direction in the Convert box: YAML to JSON, or JSON to YAML. Then paste your text, or drop a .yaml, .yml or .json file on the box. A file name ending in .json or .yaml switches the direction for you.
- The result appears as you type. Pick 2 spaces, 4 spaces or a tab for indenting JSON, and tick Sort keys alphabetically if you want a predictable order for comparing two files.
- If the text has a problem, the message gives the line and column. Press Show the problem in the text to jump the cursor there, fix it, and the result updates by itself.
- Press Copy result or Download. Use result as input turns the output around, which is a quick way to check that a round trip gives you the same data.
A small configuration and its JSON
Take the YAML lines "name: Demo", "ports: [80, 443]" and a block "owner:" with two indented lines, "name: Ana" and "admin: true". The JSON result has the key "name" with the text "Demo", the key "ports" with the list 80 and 443 as numbers, and "owner" as an object holding "name" as text and "admin" as the value true.
Going back the other way writes "ports:" followed by two list lines starting with a dash. Words that could be read as something else, such as the text "true" or "123", are put in double quotes so they stay text when the file is read again.
What the converter understands
YAML to JSON handles mappings and lists written with indentation, lists and maps written in brackets and braces, plain and quoted text, comments, literal blocks that start with a pipe and folded blocks that start with a greater-than sign. Anchors (&name), aliases (*name) and merge keys (<<) are expanded into plain copies, because JSON has no way to point at another value.
Plain values follow the YAML 1.2 core rules: true and false are booleans, null and a tilde are null, whole numbers and decimals become numbers, and 0x and 0o prefixes are read as hexadecimal and octal. Words such as yes, no and on stay text, which is how current YAML parsers treat them. Older tools that follow YAML 1.1 may turn them into booleans, so check the file you are feeding into another program.
What it refuses on purpose
Tags such as !!str and custom types, complex keys that start with a question mark, and files with more than one document separated by --- are refused with a message instead of being guessed at. Tabs in indentation, keys that appear twice in one mapping, aliases that point to nothing and unclosed quotes or brackets are errors with a line and column.
Documents that use aliases to repeat large structures are cut off at two million values so that a small file cannot freeze the page. Nesting deeper than 120 levels is refused for the same reason. Nothing in the text is ever run or fetched.
Going from JSON to YAML
The JSON is checked first with a strict reader that names the position of the first error, so a trailing comma or a single-quoted string is caught the same way in every browser. The YAML output uses block style, quotes only the text that needs it, and writes multi-line text as a literal block when that is safe.
To format or validate JSON on its own, use the JSON formatter and validator. For TOML files there is the TOML and JSON converter, and for tables of data the CSV and JSON converter.
Assumptions and limits
- Dates and times such as 2020-01-02 stay as text. Some YAML libraries turn them into date objects, which JSON cannot hold.
- Integers larger than 9,007,199,254,740,991 stay as text so that no digits are lost. JSON numbers that large lose precision in JavaScript, so very large numbers in JSON input are rounded.
- Positive and negative infinity and not-a-number values are valid in YAML but cannot be written in JSON, so converting them gives an error that names where they are.
- Key order is kept as written unless you ask for sorting. Mapping keys that are not text, such as 1 or true, become the text of the key in JSON.
Frequently asked questions
Is my YAML sent to a server to be converted?
No. The text is read and written by code running in your browser tab, so a configuration file with passwords or keys in it never leaves your device.
Why does the text yes stay a string instead of becoming true?
This converter follows the YAML 1.2 rules, where only true and false are booleans. Older YAML 1.1 readers also accepted yes, no, on and off, so a file that depends on that may need quotes or explicit true and false values.
Can it convert a file with several YAML documents?
Not in one pass. A file with several documents separated by three dashes is refused with a message. Split it at the separators and convert each document on its own.
What happens to comments when I convert?
Comments are dropped, because JSON has no comments. Converting JSON to YAML cannot bring them back, so keep the original YAML file if the comments matter.