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
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.
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
| String | YAML | Why |
|---|---|---|
| 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 text | plain text | Nothing special: left plain. |
| http://example.com/a?b=1 | http://example.com/a?b=1 | A colon not followed by a space is fine: left plain. |
How multi-line strings are written
| JSON | YAML | Rule |
|---|---|---|
| {"s":"one\ntwo"} | s: |- ⏎ one ⏎ two | No final line break: strip indicator -. |
| {"s":"one\ntwo\n"} | s: | ⏎ one ⏎ two | One final line break: the plain | (clip). |
| {"s":"one\n\n"} | s: |+ ⏎ one ⏎ | Extra final line breaks: keep indicator +. |
| {"s":" one\ntwo"} | s: |2- ⏎ one ⏎ two | First 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
| Feature | YAML | JSON result |
|---|---|---|
| Block mapping and sequence | a: ⏎ - 1 ⏎ - b: 2 ⏎ c: 3 | {"a":[1,{"b":2,"c":3}]} |
| Sequence at the key’s own indent | a: ⏎ - 1 ⏎ - 2 | {"a":[1,2]} |
| Flow sequence and mapping | a: [1, "x", {b: c}] | {"a":[1,"x",{"b":"c"}]} |
| Comments | # note ⏎ a: 1 # trailing | {"a":1} |
| Double-quoted escapes | a: "tab\there \u00e9" | {"a":"tab\there é"} |
| Single-quoted | a: '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)
| YAML value | JSON value |
|---|---|
| null | null |
| ~ | null |
| true | true |
| FALSE | false |
| 42 | 42 |
| -0 | 0 |
| 007 | 7 |
| 0x1F | 31 |
| 0o17 | 15 |
| 1e3 | 1000 |
| .5 | 0.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
| Case | YAML | Position | Message |
|---|---|---|---|
| Anchor | base: &b ⏎ x: 1 | line 1, column 7 | Anchors (&name) and aliases (*name) are not supported. Write the value out in full. |
| Alias | a: 1 ⏎ b: *x | line 2, column 4 | Anchors (&name) and aliases (*name) are not supported. Write the value out in full. |
| Tag | a: !!str 1 | line 1, column 4 | Tags (such as !!str or !custom) are not supported. |
| Second document | a: 1 ⏎ --- ⏎ b: 2 | line 2, column 1 | This file has more than one YAML document. Only a single document is supported. |
| Tab indentation | a: 1 ⏎ b: 2 | line 2, column 1 | Tabs cannot be used for indentation in YAML. Use spaces. |
| Plain scalar on two lines | a: one ⏎ two | line 2, column 3 | Unexpected indentation. A value cannot continue on the next line unless it is in quotes or a | or > block. |
| Infinity | a: .inf | line 1, column 4 | .inf has no JSON equivalent (JSON cannot hold infinity or NaN). Quote it to keep it as text. |
| Duplicate key | a: 1 ⏎ a: 2 | line 2, column 1 | Duplicate key “a”. Keys in a mapping must be unique. |
| Unclosed bracket | a: [1, 2 | line 1, column 4 | The [ starting here is never closed. |
How to convert JSON to YAML
- 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.
- Paste your data. Replace the example with your JSON or YAML. The result updates as you type.
- Set the options. Choose an indent of 2 or 4 spaces, and tick “Sort keys” to put every object’s keys in alphabetical order.
- 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.
- 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
More free tools
- JSON Formatter & ValidatorValidate JSON with the exact line and column of any error, then pretty-print, minify or sort keys. Big numbers keep every digit. Runs in your browser.
- CSV to JSON ConverterConvert CSV to JSON or JSON to CSV in your browser. Handles quoted fields, line breaks, any delimiter, and shows the exact line and column of an error.
- Markdown Table GeneratorBuild a GitHub Markdown table from an editable grid or pasted CSV, TSV or spreadsheet cells. Set column alignment, pad columns, and parse a table back.
- Word CounterCount words, characters, sentences and reading time, and check your text against X, LinkedIn, Instagram, SMS and meta description limits.
- Case ConverterConvert text to UPPERCASE, lowercase, Title Case, Sentence case, camelCase, PascalCase, snake_case, kebab-case or CONSTANT_CASE. Stays in your browser.
- Remove Duplicate LinesRemove duplicate lines from a list, keep the first or last copy, and sort A to Z, naturally or at random. Works in any language and stays in your browser.