↑↓ to move ↵ to open Esc to close Browse all tools

YAML to JSON

Paste YAML to get JSON, or JSON to get YAML. Errors show the line, the column and the likely cause, and your config files never leave your browser.

Paste YAML or drop a .yaml or .yml file. The result updates as you type.
YAML version
JSON result -

Paste YAML to convert it.

Output

The JSON appears here.

Your YAML and JSON are converted in your browser. Nothing is uploaded.

Convert YAML to JSON and JSON to YAML

YAML and JSON describe the same kinds of data: mappings of keys to values, lists, text, numbers, true and false, and null. YAML is written for people, with indentation instead of brackets and room for comments. JSON is stricter, with brackets, quotes and no comments, which makes it simple for programs to read. This YAML to JSON converter turns one into the other in both directions, and on the way it checks that the input is valid, so you can also use it to validate a config file before you deploy it.

The conversion runs in a background thread of your browser, so even large files do not freeze the page, and nothing you paste is uploaded. To tidy up JSON, use the JSON formatter. To get a spreadsheet out of the result, the JSON to CSV converter takes over, and the CSV to JSON converter goes the other way.

Errors by line and column, in plain English

When the YAML is invalid, you see the line and column where the parser stopped, a short explanation of the likely cause and a button that jumps to the spot. These are the mistakes behind most broken YAML:

  • Tabs for indentation. The YAML 1.2.2 spec says tab characters must not be used in indentation, because different systems treat tabs differently. Only spaces may start a line. The tool offers to replace those tabs with spaces.
  • Indentation that does not line up. All keys of one mapping, and all items of one list, have to start in the same column. One space too many or too few moves a line into a different level.
  • Duplicate keys. The spec defines a mapping as a set of key and value pairs in which each key is unique, so a second name: in the same mapping is an error, not an update.
  • Unclosed quotes. A string that opens with a quote and never closes swallows the lines after it. The error points to where the string starts.
  • A colon inside a value. In title: Note: read me, the second colon followed by a space starts another key. Put the value in quotes.
  • Reserved characters. The spec reserves @ and the backtick for future use, so a value cannot start with them unless it is quoted.

Pasting JSON into the YAML side works too, because YAML 1.2 was designed as a superset of JSON. In the other direction the input must be strict JSON, and errors such as a trailing comma or single quotes are reported with their position.

YAML 1.1 versus YAML 1.2: yes, no, on and off

The YAML 1.2.2 spec says the 1.2 release focused on making YAML a strict superset of JSON and removed many of the problematic implicit typing rules of earlier versions. Under the core schema that this converter uses by default, only true, True, TRUE, false, False and FALSE are booleans, and octal numbers need a 0o prefix. Many tools still follow YAML 1.1, though, and there the same text can mean something else. The documentation of the yaml library that powers this tool lists the differences:

Plain valueYAML 1.2 (this tool)YAML 1.1
yes, no, on, off, y, nTexttrue or false
country: NOThe text "NO"false
mode: 0755755493 (octal)
mode: 0o755493The text "0o755"
1_000The text "1_000"1000
3:25:45The text "3:25:45"12345 (base 60)
2001-12-14TextA timestamp

The second row matters for lists of country codes: under YAML 1.1, Norway's code NO turns into false. A key named on becomes true in the same way. This converter reads YAML 1.2, and whenever your input contains values that a YAML 1.1 parser would read differently, it lists them with their line and both readings. Switch YAML version to 1.1 to see the output an older parser would produce. When you write YAML, leave Quote values YAML 1.1 parsers misread on, and words such as "no" and "on" get quotes, so every parser keeps them as text.

Multiple documents, anchors and merge keys

One YAML file can hold several documents, each starting with a line of three dashes (---). The spec treats every document as completely independent. Choose All as a JSON array to get all of them in one array, or One at a time to convert a single document. Going from JSON to YAML, Array items as separate documents writes each item of a top-level array as its own document.

An anchor (&name) marks a value, and an alias (*name) repeats it later. According to the spec, an alias refers to the most recent value with that anchor before it, and an alias whose anchor does not come earlier in the document is an error. JSON has no references, so each alias is replaced by a full copy. Merge keys (<<: *defaults) copy the entries of another mapping into the current one. The yaml library documentation notes that merge keys are a YAML 1.1 feature that is not part of the 1.2 spec. Because many config files rely on them, they are applied here unless you switch Merge keys off. Aliases can also be abused to make a small file expand into a huge amount of data. The yaml library guards against such expansion attacks by limiting how often aliases may repeat, and the tool then stops with a message instead of hanging.

What JSON cannot hold

  • Comments are left out, because JSON, as defined in RFC 8259, has no comments.
  • JSON keys are always text. Keys such as 1, true or null become "1", "true" and "null", and a notice tells you.
  • .inf and .nan become null, because JSON has no infinity or NaN.
  • Custom tags like !Ref are dropped and their values kept. The program that reads the YAML gives them their meaning.
  • Whole numbers keep every digit. RFC 8259 warns that many programs read numbers as 64-bit floating point values, so a very long ID may still lose digits in the program that reads the JSON.

How to use the YAML to JSON converter

  1. 1Pick YAML to JSON or JSON to YAML, then paste your text, drop a file on the box or open one.
  2. 2If an error appears, read the cause, jump to the line and column, and fix it. The result updates as you type.
  3. 3Choose the format: indent and minified JSON, or indent and quotes for YAML. Check the notes on YAML 1.1 values.
  4. 4Copy the result or download it. Swap sends the result back as input, so you can check the round trip.

Frequently asked questions

Is my YAML or JSON uploaded anywhere?

No. Both directions run in your browser, in a background thread on your own device. Config files can hold passwords, tokens and internal host names, and none of it is sent to a server. Copy link only shares your settings, never the text.

Which YAML version does the converter read?

YAML 1.2 with its core schema, the version the YAML spec recommends by default. Switch YAML version to 1.1 to read a file the way an older parser that follows YAML 1.1 does, where yes and no are booleans and 0755 is an octal number. A document that starts with the directive %YAML 1.1 is read with the 1.1 rules either way.

Why does it say tabs are not allowed?

The YAML spec forbids tab characters in indentation, because different systems treat tabs differently. Only spaces may start a line. The error shows the line, and a button replaces every tab at the start of a line with spaces for you. Tabs inside a value, after the indentation, are fine.

What happens to comments, anchors and merge keys?

JSON has no comments, so they are left out. Anchors and aliases are resolved: every *alias is replaced by a full copy of the value marked with the matching &anchor. Merge keys (<<) are applied while Merge keys is switched on, so the merged entries appear in each mapping.

How are files with several documents converted?

A YAML file can hold several documents separated by lines of three dashes (---). With All as a JSON array, each document becomes one item of a JSON array. With One at a time you pick a document and get just that one as JSON. Going the other way, Array items as separate documents writes each item of a JSON array as its own YAML document.

Why are some values quoted in the YAML output?

A value gets quotes when it would otherwise be read as something else, such as "true", "123", text that starts with a special character, or text that contains a colon followed by a space. With Quote values YAML 1.1 parsers misread switched on, words like "yes", "no", "on" and "off" get quotes too, so older parsers keep them as text.

Are long numbers and key order kept?

Yes. Whole numbers of any length keep every digit in both directions, so an ID like 12345678901234567890 does not turn into 12345678901234567000. Keys stay in the order of your file, including keys that look like numbers, which JavaScript objects would otherwise move to the front.