Skip to content

YAML to JSON Converter

Paste YAML to get JSON, or JSON to get YAML. The converter reads the common core of YAML 1.2 — mappings, lists, flow collections, quoted and block scalars, anchors and aliases, merge keys and multiple documents — and tells you the line and column of the first thing it cannot read, with the line itself shown. Key order is kept, strings that could be mistaken for numbers or booleans are quoted on the way back, and words such as NO and versions such as 1.10 are flagged. It runs in your browser; nothing is uploaded. Free, no sign-up.

Direction

Converted in your browser as you type. Nothing is uploaded.

Options

Paste some YAML or JSON, or load the example, to convert it.

How to Use the YAML to JSON Converter

  1. 1. Choose a direction. YAML → JSON parses YAML and writes JSON; JSON → YAML does the reverse. Load the example fills in a short service configuration for either direction.
  2. 2. Paste your text. The result updates as you type. If something cannot be read, the tool shows the line and column, a plain-English reason, and the offending line with a caret under the column.
  3. 3. Set the options. For JSON output, choose 2 spaces, 4 spaces, a tab or one minified line. For YAML output, choose 2 or 4 spaces and whether multi-line strings become | blocks. For YAML input, choose whether << merge keys are applied.
  4. 4. Read the notes, copy or download. Warnings list the values worth a second look. Use the result as input and swap direction checks a round trip in one click.

What It Reads, and What It Does Not

This is a parser written for the converter, not a wrapper around a library, and it covers the YAML that configuration files use. Anything outside that is reported with its position instead of being guessed at.

SupportedNot supported
Block mappings and lists, nested by indentation, including a list at the same indent as its keyTabs as indentation (YAML forbids them; the tool says where)
Flow collections such as [a, b] and {a: 1}, across several lines, with commentsComplex keys: a list or mapping used as a key
Plain, single-quoted and double-quoted scalars with every YAML escape, folded across lines%TAG directives (a %YAML line is accepted)
Block scalars | and > with +, - and an indentation digitApplication tags such as !Ref or !Sub: the value is kept and the tag is ignored with a warning
Comments, and several documents separated by --- and ...YAML 1.1 types: timestamps, sets, ordered maps, binary data and base-60 numbers are read as plain text
Anchors, aliases and the << merge key (switchable)An anchor or tag written before a key (ignored with a warning)
The core tags !!str, !!int, !!float, !!bool, !!null, !!seq and !!map, and explicit ? key for a scalar keyOutput larger than about five million characters (aliases can expand a small file a long way)

How YAML Values Become JSON

YAML decides a plain value's type from how it is written. This tool follows the YAML 1.2 core schema, which is what current parsers use.

Written in YAMLBecomes in JSONWhy
true, True, FALSEtrue, true, falseOnly these spellings are booleans.
yes, NO, on, off"yes", "NO", "on", "off"Booleans in YAML 1.1, text in 1.2. The tool warns, because an older parser would disagree.
~, null, an empty valuenullThe three ways to write null.
0x1F, 0o17, 00731, 15, 7Hexadecimal, octal with the 1.2 prefix, and leading zeros ignored.
1.101.1A float: the trailing zero is lost. Quote it, "1.10", to keep the text.
2024-01-01, 12:30"2024-01-01", "12:30"The core schema has no date or time type, so they stay text.
.inf, .nannullJSON has no infinity or NaN. The tool says so.
1234567890123456789012345678901234567890Large integers keep every digit.

A Worked Example

The YAML example has ten top-level entries and sixteen keys in all, two levels deep. A few lines show the rules at work.

In the YAMLIn the JSON
ratio: 0.75 and replicas: 3"ratio": 0.75 and "replicas": 3, as numbers
TIMEOUT: "30""TIMEOUT": "30", still text because it was quoted
description: > with two folded lines"A long description that is folded into one line.\n", one line with a closing line break
staging: with <<: *defaults and region: usstaging gets retries: 3 from the anchor and keeps its own region: us
# Service configurationDropped: JSON has no comments

Going from JSON to YAML

The JSON parser is strict and keeps key order and numbers exactly as written, so 10.0 stays 10.0. On the way out, a string is left plain only when every YAML reader, old or new, would read it back as the same string. So "NO", "1.10", "30", "null", "2024-01-01" and strings with a leading indicator or an embedded : or # are written with quotes, and strings with line breaks become | blocks (|- when they do not end in a break, |+ when they end in several). Empty collections are written {} and []. If an object repeats a key, the last value wins and the tool warns.

Errors, in Plain Words

  • Indentation. A tab used for indentation, or a line that does not line up with its siblings, is reported at that line.
  • A missing or misplaced colon. A line in a mapping with no key: value shape, or a plain value that contains a colon and a space, such as title: Note: draft, is reported; quote the value to fix it.
  • Quotes and brackets that never close. The error points at where the quote or bracket opened.
  • Duplicate keys and unknown aliases. YAML requires unique keys, so a second name: in the same mapping is an error that names the first line.
  • JSON mistakes. A trailing comma, single quotes, an unquoted key, a comment, a leading zero, NaN or text after the end each get their own message.

Use the real parser in production

This converter is for inspecting, converting and debugging files. For a pipeline, use the maintained YAML library for your language, and check which YAML version it implements; the differences listed above are where parsers disagree.

Frequently Asked Questions

How do I convert YAML to JSON?
Paste the YAML into the box with the direction set to YAML → JSON. The JSON appears as you type, with the indentation you chose. Copy it or download it as a file. If the YAML has several documents separated by three dashes, the JSON is an array with one item per document.
Why did country: NO or version: 1.10 change?
Under YAML 1.2, NO is text, but under YAML 1.1 it is the boolean false, so the tool warns that an older parser would read it differently. An unquoted 1.10 is a number, and numbers do not keep trailing zeros, so it becomes 1.1. Quote values like these in the YAML if you want them kept as text.
What happens to comments?
They are dropped when converting to JSON, because JSON has no comments. Converting JSON to YAML cannot bring them back. If you need to keep comments, edit the YAML and convert a copy.
Does it support anchors, aliases and merge keys?
Yes. An alias is replaced by a copy of the anchored value, and a << key copies the keys of the mapping (or list of mappings) it points to, with the mapping's own keys taking priority. Merge keys come from YAML 1.1 and are widely supported but are not in the YAML 1.2 specification, so you can turn them off to keep << as an ordinary key.
Is key order kept?
Yes, in both directions. JavaScript objects normally move keys that look like numbers to the front, so the tool keeps its own ordered maps and writes the JSON itself, which keeps the order you wrote.
Why do I see “a key: value is not allowed here”?
A plain value cannot contain a colon followed by a space, because YAML would read it as a second key. Quote the value, as in title: "Note: draft", or use a block scalar. The error shows the line and the column of the second colon.
Is my data uploaded?
No. The parsing and writing are plain JavaScript in your browser, so nothing you paste is sent to CitationEasy or anywhere else.

Related Tools

More in Data, Markup & Code

See all Data, Markup & Code