Skip to main content
ponderloop

JSON to YAML Converter

Paste JSON and get block-style YAML straight away, or switch direction and turn YAML back into JSON. The example JSON has 11 top-level keys and becomes 18 lines of YAML; 3 of its strings are put in quotes (version: "1.10", debug: "yes", released: "2024-01-15") because a YAML reader would otherwise turn them into a number, a boolean or a date, and its multi-line string becomes a | block. Empty arrays and objects stay [] and {}, and numbers keep the digits you wrote. YAML is read with the YAML 1.2 core schema, so yes, no, on and off are plain text. Errors show the line and column. Everything runs in your browser, so nothing is uploaded.

Updated Runs in your browser: nothing you enter is uploadedHow this tool works

Direction
Stays in your browser

Replace the example: paste or type your data. The result updates as you type.

Your data is converted on this device and never uploaded. It is not saved either: reload the page and it is gone. Limit: 1,000,000 characters per conversion.

Options

Result

Converted 16 keys to YAML.

  • 3 strings were put in quotes so YAML keeps them as text instead of reading them as a number, boolean, null or date.

Counts

Keys
16
Nesting depth
3
Output lines
18
Output size
258 bytes

Which strings get quotes

Each string below is a JSON string value, converted with the default settings.
StringYAMLWhy
yes"yes"A YAML 1.1 reader makes it true; written with quotes it is text in every version.
true"true"A boolean under the YAML 1.2 core schema.
null"null"Null under the core schema (so are Null, NULL and ~).
12"12"An integer under the core schema.
007"007"Still an integer (7) in YAML 1.2, so the leading zeros would be lost.
1.10"1.10"A float: it would come back as 1.1.
0x1F"0x1F"A hexadecimal integer (31).
.inf".inf"Infinity under the core schema (.nan is not-a-number).
2024-01-15"2024-01-15"A date in YAML 1.1 and in many libraries.
12:30"12:30"A base-60 number (750) in YAML 1.1.
1_000"1_000"The integer 1000 in YAML 1.1.
a: b"a: b"A colon followed by a space starts a mapping.
note #1"note #1"A space then # starts a comment.
- item"- item"A leading dash starts a list entry.
[x]"[x]"A leading bracket or brace starts a flow collection.
*star"*star"A leading * is an alias, a leading & an anchor, a leading ! a tag.
“ padded ”" padded "Plain scalars lose their leading and trailing spaces.
(empty)""An empty plain scalar is null.
plain textplain textNothing special: left plain.
http://example.com/a?b=1http://example.com/a?b=1A colon not followed by a space is fine: left plain.

How multi-line strings are written

Line breaks are shown as ⏎. The first column is the JSON, the second the YAML the tool produces.
JSONYAMLRule
{"s":"one\ntwo"}s: |- ⏎ one ⏎ twoNo final line break: strip indicator -.
{"s":"one\ntwo\n"}s: | ⏎ one ⏎ twoOne final line break: the plain | (clip).
{"s":"one\n\n"}s: |+ ⏎ one ⏎Extra final line breaks: keep indicator +.
{"s":" one\ntwo"}s: |2- ⏎ one ⏎ twoFirst line starts with a space: an indentation digit says how far the block is indented.
{"s":"a\r\nb"}s: "a\r\nb"A carriage return cannot live in a block, so the string is double-quoted.
{"s":"\nlead"}s: "\nlead"A blank first line would be ambiguous in a block, so the string is double-quoted.

YAML syntax that is read

The subset the YAML to JSON direction understands, each with the compact JSON it gives.
FeatureYAMLJSON result
Block mapping and sequencea: ⏎ - 1 ⏎ - b: 2 ⏎ c: 3{"a":[1,{"b":2,"c":3}]}
Sequence at the key’s own indenta: ⏎ - 1 ⏎ - 2{"a":[1,2]}
Flow sequence and mappinga: [1, "x", {b: c}]{"a":[1,"x",{"b":"c"}]}
Comments# note ⏎ a: 1 # trailing{"a":1}
Double-quoted escapesa: "tab\there \u00e9"{"a":"tab\there é"}
Single-quoteda: 'it''s'{"a":"it's"}
Literal block |a: | ⏎ one ⏎ two{"a":"one\ntwo\n"}
Folded block >-a: >- ⏎ one ⏎ two{"a":"one two"}
Optional --- and ...--- ⏎ a: 1 ⏎ ...{"a":1}

How a plain value is read (YAML 1.2 core schema)

The value on the right of “a: ” without quotes. Put a value in quotes to keep it as text.
YAML valueJSON value
nullnull
~null
truetrue
FALSEfalse
4242
-00
0077
0x1F31
0o1715
1e31000
.50.5
yes"yes"
no"no"
on"on"
off"off"
2024-01-15"2024-01-15"
1_000"1_000"
text"text"

YAML that is refused, and how the error reads

Line and column count from 1, as in a text editor. Line breaks are shown as ⏎.
CaseYAMLPositionMessage
Anchorbase: &b ⏎ x: 1line 1, column 7Anchors (&name) and aliases (*name) are not supported. Write the value out in full.
Aliasa: 1 ⏎ b: *xline 2, column 4Anchors (&name) and aliases (*name) are not supported. Write the value out in full.
Taga: !!str 1line 1, column 4Tags (such as !!str or !custom) are not supported.
Second documenta: 1 ⏎ --- ⏎ b: 2line 2, column 1This file has more than one YAML document. Only a single document is supported.
Tab indentationa: 1 ⏎ b: 2line 2, column 1Tabs cannot be used for indentation in YAML. Use spaces.
Plain scalar on two linesa: one ⏎ twoline 2, column 3Unexpected indentation. A value cannot continue on the next line unless it is in quotes or a | or > block.
Infinitya: .infline 1, column 4.inf has no JSON equivalent (JSON cannot hold infinity or NaN). Quote it to keep it as text.
Duplicate keya: 1 ⏎ a: 2line 2, column 1Duplicate key “a”. Keys in a mapping must be unique.
Unclosed bracketa: [1, 2line 1, column 4The [ starting here is never closed.

How to convert JSON to YAML

  1. Choose the direction. Leave “JSON to YAML” selected, or pick “YAML to JSON” to go the other way. The example switches to match until you type your own.
  2. Paste your data. Replace the example with your JSON or YAML. The result updates as you type.
  3. Set the options. Choose an indent of 2 or 4 spaces, and tick “Sort keys” to put every object’s keys in alphabetical order.
  4. Fix any error. If the input is malformed, the message gives the line and column with a caret under the spot, for example an unclosed bracket or a YAML feature this tool does not support.
  5. Copy or download. Copy the result to the clipboard or download it as a .yaml or .json file. Nothing is uploaded.

Frequently asked questions

How do I convert JSON to YAML?
Paste the JSON into the box above and copy or download the YAML. Objects become “key: value” lines, arrays become “- item” lines, and indentation shows the nesting. Because JSON is almost a subset of YAML, the structure is the same; the work is in writing each string so that YAML reads it back as the same text.
Why are some of my strings in quotes?
A plain YAML value is guessed to be a number, boolean, null or date when it looks like one. The string "12", "true", "null", "1.10" or "2024-01-15" written without quotes would come back as a different type, so those are quoted. Strings with a colon and a space, a leading dash or bracket, a “ #” or surrounding spaces are quoted for the same reason.
Is yes or no a boolean in YAML?
Not in YAML 1.2. Its core schema knows only true and false (in lower, title or upper case) as booleans, so yes, no, on and off are strings. YAML 1.1, and many libraries still built on it, read them as booleans. This tool reads them as text when converting YAML to JSON, and when writing YAML it puts such strings in quotes so both kinds of reader agree.
How are multi-line strings written?
As a | block: the lines follow, indented under the key. The indicator after the bar records the final line breaks: | keeps one, |- keeps none and |+ keeps all of them. A string with a carriage return or a leading blank line is written in double quotes with \n escapes, because a block could not hold it faithfully.
Which YAML can it convert to JSON?
One document with block mappings and sequences, flow [ ] and { } collections, plain, single- and double-quoted scalars with escapes, | and > block scalars with chomping and indentation indicators, and comments. That covers most configuration files, such as Docker Compose, GitHub Actions, Kubernetes manifests and OpenAPI files, as long as they do not use anchors.
Why does it refuse anchors, aliases and tags?
Anchors (&name), aliases (*name) and merge keys (<<) copy data from one place to another, and tags (!!type) change how a value is read. Handling them correctly means a full YAML processor, so this tool stops with the line and column instead of guessing. Replace each alias with the value it points to, then convert.
What happens to numbers like 0x1F, 007 and .5?
YAML to JSON writes them as JSON numbers from their digits: 0x1F becomes 31, 0o17 becomes 15, 007 becomes 7 (YAML 1.2 reads leading zeros as plain decimal), .5 becomes 0.5 and 5. becomes 5. A note under the result tells you when this happened. Large integers keep all their digits. .inf and .nan have no JSON form, so they are an error; put them in quotes to keep them as text.
Are comments kept?
No. JSON has no comments, so they are dropped when converting YAML to JSON, and JSON has none to carry over to YAML.
Is there a size limit?
Yes: 1,000,000 characters (about 1 MB) per conversion. Above that the page shows a notice instead of converting, so the tab stays responsive. Split a bigger file into parts.
Is my data uploaded anywhere?
No. The conversion runs in your browser and the text is never uploaded, stored or logged; it is gone when you close or reload the page. The only thing the site records, if you allow analytics, is that a button was used, never any of the data.

How it works

JSON is read by a strict RFC 8259 parser that keeps numbers as written and keys in order. It is then written as YAML 1.2 block style: mappings as “key: value”, sequences as “- item” with nested collections starting on the dash line, and empty collections as [] and {}. A string is written plain only when a YAML reader would read it back unchanged. It is tested against the core schema of YAML 1.2.2 (null, booleans, decimal, octal and hexadecimal integers, floats, .inf and .nan), against the YAML 1.1 readings that libraries still use (yes/no/on/off, dates, base-60 and underscored numbers), and against the characters that give YAML syntax a meaning. Anything that fails is double-quoted with JSON-style escapes (plus \u escapes for control and line-separator characters); a string with line breaks becomes a | block with the chomping indicator that reproduces its final line breaks. YAML is read line by line for block structure (indentation decides nesting) and character by character for quoted scalars and flow collections. Plain scalars are resolved with the core schema and written to JSON from their digits, never through a floating-point number. Anchors, aliases, merge keys, tags, directives, several documents, complex keys, tab indentation and plain scalars that continue onto the next line stop the conversion with their line and column, as do duplicate keys. Input above one million characters is not converted.

Sources

All toolsHome & DIY calculators