JSON to YAML Converter
Published Updated
Convert JSON to block-style YAML from pasted text or a .json file, with two-space indentation and no line folding. Strings that YAML could misread, such as 'yes' or '2024-01-05', are quoted so they stay strings.
How each JSON value is written
The output is block style, one key or list item per line, which is how Kubernetes and Compose files are usually written. The rows below come from running the page's own code in Google Chrome 156.
| JSON input | YAML output |
|---|---|
{"a":"yes","b":"on","c":"~"} | a: 'yes', b: 'on', c: '~', quoted |
"true", "123", "null" as strings | 'true', '123', 'null' |
"2024-01-05" | '2024-01-05', so no parser makes it a date |
"- x" and ": x" | Quoted, since a leading dash or colon changes the meaning |
"" (empty string) | '' |
"line1\nline2\n" | A | block; without the last newline, |- |
[], {}, null | [], {}, null |
1.0, -0 | 1, -0.0 |
A key such as on, yes or N is quoted as well, because an unquoted N or on was a boolean in older YAML.
Strings that get quotes or escapes, as written
The page's own conversion code ran in Google Chrome 158, Firefox 155, Playwright's WebKit build (not the Safari app) and Node.js 22.23.1 on 148 generated JSON documents. The YAML text was identical in all four, character for character. The rows below are measured outputs.
| JSON string value | YAML written (↵ = line break) | Style |
|---|---|---|
"1e3", "0x1F", "0o17", "0b101", "012", "1_000", "+1", ".5", "1:30" | '1e3', '0x1F', '0o17', '0b101', '012', '1_000', '+1', '.5', '1:30' | Quoted with single quotes |
".inf", "-.inf", ".nan" | '.inf', '-.inf', '.nan' | Quoted with single quotes |
"2026-11-26", "2026-11-26T10:00:00Z" | '2026-11-26', '2026-11-26T10:00:00Z' | Quoted with single quotes |
"web", "hello world", "a#b", "x, y", "café", "日本", "😀" | web, hello world, a#b, x, y, café, 日本, 😀 | Written bare |
" lead", "trail " | ' lead', 'trail ' | Quoted with single quotes |
"%pct", "@at", "&anchor", "*alias", "!tag", "|bar", ">gt", "[x]", "{x}", "#hash", "<<", "=" | '%pct', '@at', '&anchor', '*alias', '!tag', '|bar', '>gt', '[x]', '{x}', '#hash', '<<', '=' | Quoted with single quotes |
"a: b", "a #b", "foo: bar: baz" | 'a: b', 'a #b', 'foo: bar: baz' | Quoted with single quotes |
"tab\there", "a\r\nb", "x\ty\nz" | "tab\there", "a\r\nb", "x\ty\nz" | Double quotes with escapes, not a block |
"\u0001ctrl", "\u0007bell", "\u007fdel", "\u0085nel", "\u2028ls", "\u2029ps", "\u00a0nbsp", "\ufeffbom", "\ud800lone" | "\x01ctrl", "\abell", "\x7Fdel", "\Nnel", "\Lls", "\Pps", "\_nbsp", "\uFEFFbom", "\uD800lone" | Double quotes with escapes |
"a\nb" | |-↵ a↵ b | Literal block, strip |
"a\nb\n" | |↵ a↵ b | Literal block, clip |
"a\n\nb\n\n" | |+↵ a↵↵ b↵ | Literal block, keep |
" a\nb" | |3-↵ a↵ b | Literal block with an indentation indicator |
{"a\nb":1} | ? "a\nb"↵: 1 | A key with a line break uses the explicit ? form |
The YAML 1.2.2 specification says a plain scalar must not be empty or have leading or trailing white space, and its core schema reads patterns such as 012, 0o17, 0x1F, 1e3 and .inf as numbers. The converter quotes all of them, and also 1_000, 0b101 and 1:30.
Numbers, keys and nesting in the YAML
The page reads numbers with JavaScript, so a number is written from its 64-bit float value. MDN gives 2^53 - 1 as the largest integer that is safe, and RFC 8259 says good interoperability comes from expecting no more precision than binary64 (double precision) numbers give. Outputs in all four runtimes:
| JSON number | YAML written |
|---|---|
9007199254740993 | 9007199254740992 |
1e-7 | 1.e-7 |
5e-324 | 5.e-324 |
1.7976931348623157e308 | 1.7976931348623157e+308 |
1.50 | 1.5 |
1E+2 | 100 |
1e400 | .inf |
-1e400 | -.inf |
100000000000000000000 | 100000000000000000000 |
In all 148 documents, js-yaml 5.2.2 read the YAML back to the value JSON.parse gave, and so did this site's own YAML to JSON converter. 1e400 is valid JSON, and it becomes the YAML float .inf because JavaScript reads it as Infinity. RFC 8259 gives 1E400 as an example of a number that may cause interoperability problems.
Nesting of 500 arrays and of 500 objects converts, and 501 of either is refused with the depth message. An array of 10,001 numbers inside 498 nested objects converts, and one of 12,001 is refused by the third guard. These limits behaved the same in all four runtimes.
Error wording and speed in each browser
The page shows the browser's own JSON error text under the input, so the wording depends on the engine. The text below was read from the rendered page:
| Browser | Message under the result for a trailing comma |
|---|---|
| Chrome 158 | Expected double-quoted property name in JSON at position 7 (line 1 column 8) |
| Firefox 155 | JSON.parse: expected double-quoted property name at line 1 column 8 of the JSON data |
| WebKit build | JSON Parse error: Property name must be a string literal |
Chrome 158 and Firefox 155 give a line and column. The WebKit build names the problem and gives no position. Conversion time of one call, the median of 3 calls, in milliseconds, on generated arrays of objects (each with a string, a number, a boolean, a short list and sometimes a two-line string):
| Generated input | Node.js | Chrome 158 | Firefox 155 | WebKit build |
|---|---|---|---|---|
| 1,000 objects, 94,641 characters of JSON, 9,200 lines of YAML | 46 | 8 | 110 | 9 |
| 10,000 objects, 976,341 characters of JSON, 92,000 lines of YAML | 404 | 65 | 1,059 | 89 |
| 40,000 objects, 3,985,341 characters of JSON, 368,000 lines of YAML | 1,634 | 275 | 2,949 | 371 |
Why the quoting matters
YAML 1.2, published in 2009, was written so that every JSON file is also valid YAML, which the YAML 1.2.2 specification describes as its main aim. That makes the conversion safe for a parser that follows 1.2, but plenty of tools still follow YAML 1.1, where the boolean type accepts y, n, yes, no, on and off in any of three letter cases.
Converting a JSON file
Step 1
Paste JSON or add a .json file
Pasted text and a file both land in the same box. A file keeps its name, so the download is called after it with a .yaml ending.
Step 2
Press Convert to YAML
Invalid JSON stops with the parser's message and the position of the first bad character. Nothing is written until the text parses.
Step 3
Copy or download
The whole result is shown, not a preview. Copy puts it on the clipboard, and Download .yaml saves it as converted.yaml for pasted text.
Limits and rough edges
- Input above 5,000,000 characters is refused before parsing, and so is nesting deeper than 500 levels.
- A third guard adds up each value's depth and stops at 5,000,000, because a deep and wide document can write far more YAML than it took JSON to describe it.
- Error messages come from the browser's own JSON parser, so the wording and the position differ by browser (see the table of messages above). Single quotes, a trailing comma and a comment after the value each fail in all three browsers.
For the reverse direction, YAML to JSON Converter reads YAML. To check the JSON first, JSON Formatter shows where it breaks.
JSON to YAML questions
Why are some of my strings wrapped in single quotes?
Those strings would turn into something else if left bare. In YAML, yes, on, null, ~, 123 and 2024-01-05 can all be read as a boolean, null, number or date. Quotes keep the value a string, and a plain name like web stays unquoted.
Why did a number come out different from my JSON?
The page parses JSON with JavaScript, which stores numbers as 64-bit floats. 12345678901234567890 came out as 12345678901234567000, and 1e21 as 1.e+21. Put long IDs in quotes in the JSON to keep every digit.
Why are my keys in a different order?
JavaScript puts keys that look like whole numbers first, in ascending order. Other keys follow in the order they were written. The input {"on":1,"1":3} gave '1' first and then 'on'.
Which of two repeated keys survives?
The last one. {"a":1,"a":2} became a: 2 with no warning, because JSON.parse overwrites the first value. RFC 8259 calls the behaviour unpredictable and notes that many parsers keep only the last pair.
Why does a long string stay on one line?
The converter turns line folding off. A 199-character string came out as one line, so a diff shows one changed line. Most strings that contain a newline become | blocks. One that also holds a tab or a carriage return is written in double quotes with escapes.
Is my JSON sent to a server?
No. js-yaml writes the YAML inside the page, and the code has no network call. A config with passwords is processed in your browser; this page does not upload it.
Why is my multi-line string in double quotes instead of a | block?
It holds a tab or a carriage return. The string x, tab, y, newline, z came out as "x\ty\nz" and a CRLF line break as "a\r\nb". Plain line breaks without those characters give a | block.
Does the YAML read back to the same data?
In the test it did. Of 148 generated documents, js-yaml 5.2.2 and the YAML to JSON converter on this site gave back the value that JSON.parse produced, for every one. That includes strings such as 012, 0x1F, 1e3, .inf and 2026-11-26, a key with a colon and a space, and an empty object.
What does the converter write for 1e400?
It writes .inf. 1e400 is valid JSON, but JavaScript reads it as Infinity, and the converter writes that as the YAML float .inf. -1e400 becomes -.inf. A number above 2^53 is rounded first: 9007199254740993 came out as 9007199254740992.
Why does my JSON error look different in another browser?
The page shows the browser's own error text. For a trailing comma, Chrome 158 and Firefox 155 name a line and column, and the WebKit build says Property name must be a string literal with no position.