YAML to JSON Converter
Published Updated
Convert YAML to JSON or JSON to YAML from pasted text or a file; a .json or .yaml extension picks the direction. Dates and yes or no stay strings, 1.10 becomes 1.1, and a merge key << is not expanded.
What changes on the way to JSON
The parser follows the YAML 1.2.2 core schema, where only true and false are booleans. Results from the page's own code:
| YAML value | JSON result |
|---|---|
released: 2024-01-05 | "2024-01-05", a string, with no time added |
a: yes, b: on, c: no | Strings. Only true and false become booleans |
v: 1.10 | 1.1, as a number |
014, 0o14, 0x1F | 14, 12, 31 |
1_000 | "1_000", a string |
~, null, or an empty value | null |
.inf, -.inf, .nan | null, since JSON has no such numbers |
t: | block text | The lines joined by \n, with a final newline |
f: > folded text | Lines folded into spaces, with a final newline |
Keys become strings: 1:, true: and null: give "1", "true" and "null". They keep their order, except that keys that are whole numbers move to the front in numeric order, so b, 10, 2, a come out as "2", "10", "b", "a".
Inputs it turns down
- A file holding only comments: expected a document, but the input is empty.
- A second document after
---: expected a single document in the stream. - A repeated key: duplicated mapping key, with the line and column.
- Tabs for indentation: tab characters must not be used, with line and column.
- More than 20 aliases (21 failed, 20 worked), or tags such as
!!binaryand!!set. - More than 5,000,000 characters of input, or more than 500,000 values once aliases are expanded.
YAML 1.1 habits under js-yaml 5.2.2
The converter is js-yaml 5.2.2. These results come from the page's own code run in Node.js 22.23.1. The YAML 1.1 boolean type, a 2005 draft, listed y, yes and on and their opposites as booleans; here they stay text:
| YAML | JSON from this page |
|---|---|
countries: with the items GB, NO, SE | ["GB", "NO", "SE"]: Norway stays NO |
on: holding push:, as in a CI workflow file | A key named "on" |
y, n, Yes, NO, off | The strings "y", "n", "Yes", "NO", "off" |
True, TRUE, tRUE | true, true and the string "tRUE" |
Null, NULL, nULL | null, null and the string "nULL" |
python: 3.10, node: 22.04 | 3.1 and 22.04, both numbers |
zip: 02134, mode: 0755, 08, 010 | 2134, 755, 8, 10: read as decimal, leading zeros dropped |
0b101 | The string "0b101" |
1:30, 09:30 | The strings "1:30" and "09:30" |
2024-01-05T10:30:00Z | The same text as a string |
!!str 0755, !!int '42' | "0755" and 42: a tag decides the type |
The other direction plans for older readers: JSON to YAML wrote the strings "yes", "NO", "on", "0755", "2024-01-05" and "1.10" in single quotes, and quoted even a key named n.
The error messages, word for word
What the page shows for common mistakes. The two numbers in brackets are line and column, both counted from 1:
| YAML | Message |
|---|---|
a: 1, b: 2, a: 3 | Couldn't parse this as valid YAML: duplicated mapping key (3:1) |
a:, then a tab before b: 1 | Couldn't parse this as valid YAML: tab characters must not be used in indentation (2:1) |
a:, b: 1, c: 2 | Couldn't parse this as valid YAML: bad indentation of a mapping entry (3:2) |
a: "open, b: 2 (quote not closed) | Couldn't parse this as valid YAML: deficient indentation (2:1) |
a: [1, 2, b: 3 (bracket not closed) | Couldn't parse this as valid YAML: deficient indentation (2:1) |
a:1, b: 2 (no space after the colon) | Couldn't parse this as valid YAML: end of the stream or a document separator is expected (2:2) |
a: 1, ---, b: 2 | Couldn't parse this as valid YAML: expected a single document in the stream, but found more |
a: !Ref MyBucket | Couldn't parse this as valid YAML: unknown scalar tag !<!Ref> (1:4) |
a: !!timestamp 2024-01-05 | Couldn't parse this as valid YAML: unknown scalar tag !<tag:yaml.org,2002:timestamp> (1:4) |
| 21 aliases of one anchor | Couldn't parse this as valid YAML: aliases exceeded maxAliases (20) (22:7) |
a: &a, b: *a (an anchor inside itself) | This YAML contains a circular reference (an anchor that refers back to itself), which can't be converted to JSON. Please remove the cycle and try again. |
A quote or bracket left open is reported as deficient indentation on the following line, so look one line up. Accepted without a message: a leading ---, a closing ..., a tab after a colon, a byte order mark at the start and CRLF line endings.
The JSON it writes, checked in three browsers
A 20-key YAML document went through the real tool component in Google Chrome 157, Firefox 155 and Playwright's WebKit build (not the Safari app). All three wrote the same 519-byte converted.json, with an identical SHA-256, indented by two spaces and with no line break at the end. Values from it that the tables above do not cover:
| YAML | JSON written |
|---|---|
near: 9007199254740993 | 9007199254740992, rounded to a number JavaScript can store |
sci: 1e21 | 1e+21 |
huge: 1e400 | the string "1e400": too large for a number, so it stays text |
negzero: -0 | 0 |
esc: "\u00e9 \U0001F642" | "é 🙂": escapes in double quotes are decoded |
東京: 1 | the key "東京", written as it is, not escaped |
<<: *b next to y: 3 | a key "<<" holding the anchored map, beside "y": 3: the merge is not applied |
| a list used as a key, ? [1, 2] | "Couldn't parse this as valid YAML: object-based map does not support complex keys (1:1)" |
just text, a single value | "just text", a JSON string |
Downloads, names and limits in the browser
- Pasted text downloads as converted.json, or converted.yaml in the JSON to YAML direction. A file keeps its name with the new extension: config.yml gives config.json, notes.txt gives notes.json and a file named noext gives noext.json.
- Choosing config.yml or deploy.YAML switches the page to YAML to JSON, and data.json to JSON to YAML (data.yaml). A .txt file keeps the direction already chosen, and Reset goes back to YAML to JSON.
- The downloads are typed application/json and application/x-yaml, and the card shows the name and size, such as "config.json · 12 B".
- The preview stops at 50 lines: a 120-line result ended with "… (70 more lines)". Copy and Download hold the whole result.
- A .yaml file that starts with a byte order mark converts, and the mark does not appear in the text box.
- 5,000,000 characters converted, in 453 to 1,240 ms (one run in each engine); 5,000,001 were refused within 46 ms with "This YAML is too large to convert (more than 5,000,000 characters)." The alias limit held as well: 23,808 list items behind 20 aliases gave 3,500,084 characters of JSON in 33 to 49 ms, and 23,809 were refused in 11 to 17 ms.
Speed was measured on generated records of six keys each, one of them a nested map and one a two-item list, from the Convert click until the download link appeared (median of 5 runs):
| Input | Chrome 157 | Firefox 155 | the WebKit build |
|---|---|---|---|
| YAML to JSON, 1,000 records (102,343 characters; 177.1 KB of JSON) | 9 ms | 14 ms | 9 ms |
| YAML to JSON, 10,000 records (1,043,475 characters; 1.75 MB) | 66 ms | 139 ms | 57 ms |
| YAML to JSON, 40,000 records (4,240,574 characters; 7.06 MB) | 393 ms | 549 ms | 217 ms |
| JSON to YAML, 1,000 records (99,344 characters; 108.7 KB of YAML) | 10 ms | 22 ms | 11 ms |
| JSON to YAML, 10,000 records (1,013,476 characters; 1.08 MB) | 73 ms | 174 ms | 89 ms |
| JSON to YAML, 40,000 records (4,120,575 characters; 4.39 MB) | 350 ms | 703 ms | 339 ms |
Converting a file
Step 1
Paste text or add a file
A .yaml or .yml file switches the page to YAML to JSON, and a .json file to JSON to YAML. A .txt file or pasted text keeps the direction you chose.
Step 2
Press Convert
Parse errors name the problem, with line and column where the parser has them. Size and alias limits get their own messages.
Step 3
Copy or download
The preview shows the first 50 lines. Copy takes the whole result, and Download saves it under the file's name with a new extension.
The other direction
JSON to YAML parses with the browser's own JSON parser, then writes block style with no line folding. Strings that YAML could misread are quoted: "yes", "true", "1.10", "2024-01-05" and "null" come out in single quotes, and so does a key named on. Multi-line strings become | blocks, and non-ASCII text such as café is left as it is. Input over 5,000,000 characters or nested beyond 500 levels is refused.
For one-way JSON work, JSON to YAML Converter does the same job on its own page. To tidy JSON first, use JSON Formatter.
JSON to YAML: values and the browser's own messages
In this direction the JSON is read by the browser's parser, so a syntax error carries that browser's wording. YAML errors come from js-yaml and read the same in all three browsers. Three common mistakes:
| JSON | Chrome 157 | Firefox 155 | the WebKit build |
|---|---|---|---|
| {"a":1,} | Expected double-quoted property name in JSON at position 7 (line 1 column 8) | JSON.parse: expected double-quoted property name at line 1 column 8 of the JSON data | JSON Parse error: Property name must be a string literal |
| {'a':1} | Expected property name or '}' in JSON at position 1 (line 1 column 2) | JSON.parse: expected property name or '}' at line 1 column 2 of the JSON data | JSON Parse error: Single quotes (') are not allowed in JSON |
| a: 1 (YAML pasted in this direction) | Unexpected token 'a', "a: 1" is not valid JSON | JSON.parse: unexpected character at line 1 column 1 of the JSON data | JSON Parse error: Unexpected identifier "a" |
Each message follows "Couldn't parse this as valid JSON:" on the page. The YAML written was the same in the three browsers:
- 1e21 is written 1.e+21 and -0 as -0.0. Converted back to JSON (with the tool's code in Node.js), they come out as 1e+21 and 0.
- 12345678901234567890 is written 12345678901234567000, already rounded when the JSON is read.
- A string holding CR LF or a tab is written in double quotes with \r\n or \t; a string with a plain line break becomes a |- block.
- {} and [] stay {} and []; null stays null; a key named __proto__ is kept as an ordinary key.
- 500 nested arrays convert. At 501 the page says the JSON is more than 500 levels deep.
YAML and JSON questions
Why did my version number 1.10 turn into 1.1?
Unquoted, 1.10 is a number, and JSON writes numbers without a trailing zero. Quote it in the YAML as '1.10' to keep a string. The same goes for values like 012 or 1e3.
Why is there a key named << in my output?
Merge keys are a YAML 1.1 feature, defined in a 2005 draft, and this converter follows the YAML 1.2 core schema, so << is read as an ordinary key. Write the shared keys out in full before converting.
Does it keep comments and anchors?
Comments are dropped, since JSON has none. Anchors and aliases are expanded into copies. More than 20 aliases in one file is refused, and so is an expansion above 500,000 nodes.
Why does it say it expected a single document?
A file with --- separators holds several YAML documents, and JSON can hold one value. Convert each document on its own.
Can it handle large numbers?
Only up to what JavaScript stores exactly. In the test, 12345678901234567890 came out as 12345678901234567000. Quote long IDs in the YAML to keep every digit.
Is my file sent anywhere?
It is processed in your browser; this page does not upload it. Parsing and writing both use the js-yaml library inside the page.
Does NO, the country code for Norway, become false?
No. A list holding GB, NO and SE came out as ["GB", "NO", "SE"]. js-yaml 5.2.2 reads YAML 1.2, where only true and false in three spellings are booleans, so yes, no, on, off, y and n all stay strings.
Why did my ZIP code lose its leading zero?
Unquoted, 02134 is a number in YAML 1.2, read as decimal, so it becomes 2134; 0755 becomes 755 and 08 becomes 8. Put quotes around codes, IDs and file modes ('02134') and they stay strings with every digit.
Why does an unclosed quote say deficient indentation?
The parser keeps reading the quoted text onto the next line and only fails there. a: "open followed by b: 2 gives deficient indentation (2:1), pointing at line 2, while the missing quote is on line 1. An unclosed [ gives the same message.
Why is a small YAML file refused as too large?
Aliases are expanded before the JSON is written, and the result may hold at most 500,000 values, counting each list and map as one. 20 aliases of one 23,808-item list, 47,776 characters of YAML, converted to 3,500,084 characters of JSON; with 23,809 items the page refused it as expanding into too large a document.
Why does the error message change from one browser to another?
In the JSON to YAML direction the message is the browser's own JSON parser message. For {"a":1,} Chrome 157 said "Expected double-quoted property name in JSON at position 7 (line 1 column 8)", Firefox 155 said "JSON.parse: expected double-quoted property name at line 1 column 8 of the JSON data", and the WebKit build said "JSON Parse error: Property name must be a string literal". YAML errors come from js-yaml, and they and the converted files were the same in all three.
Why is 1e400 still in quotes in my JSON?
It is past the largest number JavaScript can hold, so the parser keeps it as the string "1e400" instead of turning it into infinity. 1e21 is in range and becomes the number 1e+21. Chrome 157, Firefox 155 and the WebKit build gave the same result.
How big a YAML file can it convert?
Up to 5,000,000 characters; one more is refused before parsing. A generated file of 40,000 records, 4,240,574 characters long, converted to 7.06 MB of JSON in a median of 393 ms in Chrome 157, 549 ms in Firefox 155 and 217 ms in the WebKit build.
Why does the preview end with a number of more lines?
The preview shows the first 50 lines of the result and counts the rest: a 120-line result ended with "… (70 more lines)". Copy and Download always give the whole result.