YAML to JSON Converter
Convert YAML to JSON or JSON to YAML as you type. The converter reads the YAML that configuration files use – nested mappings and lists, anchors and aliases, blocks of text, comments and several documents in one file – and points to the exact line and column when something is wrong.
Convert YAML and JSON
Warnings
Everything is converted locally in your browser – nothing you paste is sent to a server.
How to use the YAML to JSON converter
- Choose the direction: YAML → JSON or JSON → YAML. If there is already a result, switching moves it into the input box, so you can convert it back.
- Paste or type your text into the input box, or load one of the examples. The output updates as you type.
- Pick the output format: 2 or 4 spaces of indentation, minified JSON on one line, keys sorted
A–Z and, for YAML output, whether short lists of plain values go on one line, like
[a, b]. - If the YAML holds several documents separated by
---, choose between one JSON array with all of them and a single document. - If the input has a mistake, the output box shows the line, the column and what is wrong. Show in input puts the cursor on that spot.
- Copy the result, or download it as a
.jsonor.yamlfile.
How it works
The page reads YAML with its own parser, written for this tool, without any library. The parser builds a tree of mappings (key–value pairs), lists and single values, and the tree is then written out as JSON. The other direction reads JSON with its own strict parser, so mistakes get a line and column too, and writes the same tree as YAML.
The interesting part is the type of a plain, unquoted YAML value. The converter follows the YAML 1.2 core schema, the default of the current YAML specification:
| Plain YAML value | Becomes in JSON |
|---|---|
~, null, empty value | null |
true, False, TRUE | true or false |
42, -7, 0o17, 0x1F | 42, -7, 15, 31 |
1.5, .5, 6.02e23 | 1.5, 0.5, 6.02e23 |
.inf, .nan | null with a warning (JSON has no infinity) |
yes, no, on, off | strings: "yes", "no", … |
2026-10-17, 1_000, 12:30 | strings |
A value in single or double quotes is always a string, and so is a block of text. Numbers keep the
digits you wrote, so 1.10 stays 1.10 and a 20-digit ID is not rounded. Only
forms that JSON does not accept are rewritten: 0x1F becomes 31,
012 becomes 12, +5 becomes 5 and .5
becomes 0.5.
When writing YAML, every string is checked against the same rules in reverse. Text that would be
read back as something else gets quotes: 'yes', '1.0',
'null', '2026-10-17', an empty string, text with a space at the start or
end, text containing : or #, and text that starts with a character YAML
reserves, such as *, &, ! or [. Words like yes,
no, on and off are quoted too, so tools that still follow the older YAML 1.1 rules read them as text.
Single quotes are used unless the text contains control characters; then double quotes with escapes
such as \t. Text with line breaks becomes a literal block (|,
|- or |+) whenever that keeps every character exact.
Examples
Example 1 – types, with JSON indentation set to 2 spaces. This YAML:
name: shop-web
replicas: 3
version: 1.10
enabled: yes
ports: [8080, 8443]
becomes:
{
"name": "shop-web",
"replicas": 3,
"version": 1.10,
"enabled": "yes",
"ports": [
8080,
8443
]
}
The version is a number. If it is meant as text, write version: "1.10". The word yes
stays a string.
Example 2 – anchors and the merge key, with Minified output:
base: &base
image: web:2.4
restart: always
web:
<<: *base
restart: never
{"base":{"image":"web:2.4","restart":"always"},"web":{"image":"web:2.4","restart":"never"}}
The alias *base copies the mapping into web, and the key written after it
replaces the copied restart.
Example 3 – blocks of text, 2 spaces:
literal: |
line 1
line 2
folded: >-
one
two
{
"literal": "line 1\nline 2\n",
"folded": "one two"
}
| keeps the line breaks and > joins lines with spaces. The sign after
it decides the end: none keeps one final line break, - removes it and +
keeps all trailing ones.
Example 4 – JSON to YAML, 2 spaces:
{"answer": "yes", "version": "1.0", "empty": "", "note": "a: b", "count": 7, "tags": ["web", "api"]}
answer: 'yes'
version: '1.0'
empty: ''
note: 'a: b'
count: 7
tags:
- web
- api
With Short lists on one line switched on, the last three lines become
tags: [web, api].
Which YAML is supported
The parser covers what configuration files use in practice:
- block mappings and lists indented with spaces, nested, including lists written at the same indentation as their key;
- flow collections such as
[a, b]and{a: 1}, also across several lines; - plain, single-quoted and double-quoted values, with all YAML escapes (
\n,\t,\x41,\u00e9,\U0001F600) and line folding; - blocks of text with
|and>, the chomping signs-and+and an indentation digit; - comments, the
---and...document markers, several documents in one file and the%YAMLdirective; - anchors (
&name) and aliases (*name), which are expanded into copies, and the merge key<<; - the tags
!!str,!!int,!!float,!!booland!!null; other tags, such as a custom!Ref, are ignored with a warning.
Not supported: explicit keys written with ?, and lists or mappings used as keys (JSON
keys can only be strings anyway). YAML 1.1 extras are not applied: there are no yes/no booleans, no
1:30 base-60 numbers and no date type. Duplicate keys are reported as errors, as the
specification requires, and tabs are rejected in indentation.
Common YAML mistakes
- Tabs for indentation. YAML allows only spaces. The error message offers a button that replaces indentation tabs with two spaces.
- A colon and a space inside a value.
title: Note: read thisfails; writetitle: "Note: read this". - Numbers that should be text. Versions, postal codes and phone numbers need
quotes:
01234becomes the number 1234. - The "Norway problem". Under YAML 1.1 rules the country code
NOis read as false. YAML 1.2, used here, keeps it as text. - Uneven indentation. All keys of one mapping must start in the same column, and a nested value must be indented more than its key.
Frequently asked questions
Is JSON valid YAML?
In practice, yes: YAML 1.2 was designed so that JSON documents are also YAML. You can paste JSON into the YAML → JSON direction and it converts.
What happens to comments?
JSON has no comments, so they are dropped. Converting the JSON back to YAML gives the same data, but the comments do not return.
Does the converter keep the order of keys?
Yes. Keys appear in the order of the input, including keys that look like numbers. Turn on Sort keys A–Z to sort them by character code instead, so capital letters come first.
How are several documents handled?
A YAML file with --- separators becomes one JSON array, or you can pick a single
document. In the other direction, Top-level array as separate documents writes each item
of the array as its own YAML document.
Why does .inf turn into null?
JSON has no value for infinity or "not a number", so these become null and a warning
names the line. Quote the value if you need to keep it as text.
Is my data uploaded anywhere?
No. The conversion runs entirely in your browser with JavaScript, and nothing you paste is sent to a server. Your last input and options are kept only in this browser's local storage, so they are still there when you come back.
Related tools
- JSON Formatter — format, validate and minify JSON, with line and column errors.
- CSV to JSON Converter — turn CSV rows into JSON objects and back.
- Regex Tester — test regular expressions live against sample text.
- List Compare — find the items two lists share and the ones only one of them has.
- Word Counter — count words, characters, sentences and paragraphs.