JSON to YAML Converter for Any YAML Reader

YAML that every reader reads back as your JSON.

  • Quoting explained
  • Safe in 1.1 and 1.2
  • Read-back verified
A small clay kitchen counter with a funnel between two bowls of soft rounded beads, one bowl tidy and the other loose.

The guide

The same YAML text can mean two different things, so writing it from JSON means quoting for both readers

No, 0777, 1:30 and a bare date are strings in JSON and something else to a YAML 1.1 reader: a safe writer quotes for both versions and then proves it by reading its own output back.

  • no a string to a 1.2 reader, the boolean false to a 1.1 reader
  • 0777 777 under YAML 1.2, but 511 as a 1.1 octal number
  • 1:30 a string under 1.2, the base-60 integer 90 under 1.1
  • 1.0e+3 1e3 rewritten so every rule set reads 1000
Read the full guide Fold the guide 7 min · 16 sources

Write the word no without quotes in a YAML file and the answer depends on who reads it. A reader that follows the YAML 1.2 rules sees a string. A reader that follows the YAML 1.1 rules sees the boolean false. Nothing in the file says which rules apply, and plenty of programs still read with the older ones. A converter from JSON has to settle this before it writes a single line, because JSON has no such ambiguity: “no” is a string and nothing else.

Two rule sets, one text

The YAML 1.1 specification was published in 2005, and the 1.2 line followed in 2009, with revision 1.2.2 dated 2021-10-01. Wikipedia’s version table gives those dates. The 1.2.2 text says it defines version 1.2 and includes recommendations for processing 1.1 documents, which is a polite way of saying that both are alive.

What changed is how a plain, unquoted scalar gets its type. Under the 1.2.2 core schema, a plain scalar is null, a boolean, an integer, a float or a string, and the lists are short: true and false in three spellings, decimal integers, 0o for octal, 0x for hexadecimal, and the usual floating point forms. Everything else is a string. The 1.1 type repository is much more generous.

Its boolean type accepts y, n, yes, no, on and off in several letter cases. Its integer type accepts a leading 0 for octal, 0b for binary, underscores that are ignored, and colons for base 60. Its float type has a base-60 form too, its timestamp type turns a bare date into a point in time, and two odd types claim the plain scalars << and =.

The five traps

Each trap is a string that JSON writes without any drama.

The first is the boolean family. The country code for Norway is no, and under 1.1 rules it becomes false. The single letters y and n are booleans too, so a key named y is not what it seems.

The second is octal. The text 0777 is decimal 777 under 1.2, because the core schema has no leading-zero octal, and 511 under 1.1, because a leading 0 marks base 8. Wikipedia’s article on octal lists the leading digit 0 among the common octal prefixes, which is exactly the convention YAML 1.1 borrowed. Posix file modes and zip codes both look like this.

The third is base 60. The text 1:30 is a string in 1.2 and the integer 90 in 1.1, since each colon group is a sexagesimal place, as the sexagesimal article describes for YAML. A clock time or a ratio written that way is silently turned into minutes.

The fourth is the date. A bare 2001-12-14 matches the 1.1 timestamp expression, and a reader that supports the type returns a date object, not text.

The fifth is the odd pair. The single character = is the value key of 1.1, and one widely used reader raises an error when it meets it unquoted. The text << is the merge key.

Plain, single quoted, double quoted

Quotes are the cure, and YAML has two kinds. A single quoted scalar takes everything literally except that a single quote is doubled. A double quoted scalar understands escapes such as backslash n and backslash u followed by four hex digits. Single quotes are tidier, so the writer uses them for printable text, and moves to double quotes only when a character needs an escape: a control character, a tab, a carriage return, or a line break that no block can hold.

A scalar may stay plain only if two things hold. Every rule set it checks must read it as a string, and the text must be a legal plain scalar. The 1.2.2 specification says a plain scalar must not be empty, must not start or end with white space, and must not begin with most indicator characters. It also forbids a colon followed by a space and a space followed by a hash inside the text.

Keys follow the same rules, which is why the key y and the key on are quoted in the converter’s output. The writer is also deliberately stricter than the grammar: flow indicators such as commas and brackets are always quoted, and so is a question mark in a key or in flow style, because one common reader ends a plain scalar there. Extra quotes never change the data.

Line breaks and the chomping indicator

A string with line breaks is easiest to read as a block literal, introduced by a vertical bar. What follows the bar decides what happens to the final line breaks. The 1.2.2 specification names three behaviors: strip, clip and keep. A minus sign strips every trailing break, no indicator clips to exactly one, and a plus sign keeps them all.

So a b with one line break between and one at the end is written with a bare bar. The same text with no final break needs the bar and a minus. With two final breaks it needs the bar and a plus.

If the first line of the text starts with a space, the block also needs an indentation indicator, a digit that tells the reader how deep the content sits, since otherwise the reader would take the leading space for indentation. Some strings cannot go in a block at all: a space or tab before a line break, a carriage return, or a text made only of breaks. The writer double quotes those, with escapes, rather than guess.

Numbers that need a rewrite

JSON numbers keep their text, and the writer keeps it too, with one exception. RFC 8259 allows an exponent with no decimal point and no sign, so 1e3 is legal JSON. The 1.1 float expression requires a point and a signed exponent, so a 1.1 reader may treat 1e3 as a string while a 1.2 reader reads one thousand. Readers disagree on these forms, which is the worst kind of ambiguity, so the writer emits 1.0e+3, a form every rule set reads as one thousand. It marks each rewrite so you can see it.

The other number problems cannot be cured by any text. RFC 8259 says integers from minus to plus 2 to the power 53, less one, are interoperable, because many readers hold numbers as doubles. The largest such integer is 9007199254740991, which MDN documents through Number.MAX_SAFE_INTEGER. A value such as 12345678901234567890 is written as its digits and flagged, because a reader that stores doubles will change it. The comparison step uses BigInt so that its own check does not round.

Why library writers quote for one version

Most libraries choose one YAML version and quote only for that one. The yaml package at version 2.9.0, run for this tool, quotes 0777 and 1e3 but leaves no, 1:30 and 2001-12-14 unquoted in its default output, because under 1.2 they are plain strings. A common Python library takes the other path: it quotes no and 1:30 but leaves 1e3 and y bare, since its reader treats those as strings. Neither is wrong. Each is correct for the rules it assumes, and each hands you a file that the other reader may misread.

Proving it with a read-back

Rules written from specifications are only a claim. The page checks them by reading its own output back with the yaml package, loaded in a worker on first use. It parses the text once as version 1.2 and once as version 1.1, with integers as BigInt, and compares the result with the JSON value by value: strings exactly, numbers as exact decimals, booleans and nulls, and the key order. Any difference is listed with its JSON Pointer and what the reader returned. The output is called verified only when both versions agree.

That check found real holes while this tool was built. The package in its 1.1 mode reads 09 and 0_9 as integers, reads e1 as not a number, and reads an underscore after a point as a float, none of which the type repository pages list. The writer now quotes all of them.

A second, independent reader, run on 5,000 random documents, found that a question mark must be quoted in flow style. The rule sets named here are the 1.2.2 core and JSON schemas and the 1.1 types, and a reader with rules of its own may still differ. The honest claim is that the data reads back the same under the stated rules, not that any particular program will accept the file.

Keys, duplicates and hostile text

JSON objects with repeated names are a trap in the other direction. RFC 8259 says names should be unique, that software receiving repeated names behaves unpredictably, and that many implementations report only the last pair. The converter refuses repeated names by default, with both positions, and offers a switch that keeps the last value. MDN notes that a JSON text and the matching JavaScript expression differ only for the proto key, so the converter reads that name, like any other, as plain data that cannot touch an object’s prototype.

The reader also caps what it accepts: the size of the input, the depth of nesting, the length of one string and the count of values. A document over a cap gets a message with the cap and the place, and parsing that could take long runs in a worker that can be cancelled.

Sources

Every source consulted for this guide. Links checked November 7, 2026.

  1. YAML Ain't Markup Language (YAML) version 1.2, revision 1.2.2 YAML Language Development Team (yaml.org)
  2. YAML Ain't Markup Language (YAML) version 1.1 Ben-Kiki, Evans and Net (yaml.org)
  3. Boolean Language-Independent Type for YAML Version 1.1 yaml.org, working draft 2005-01-18
  4. Integer Language-Independent Type for YAML Version 1.1 yaml.org, working draft 2005-02-11
  5. Floating-Point Language-Independent Type for YAML Version 1.1 yaml.org, working draft 2005-01-18
  6. Timestamp Language-Independent Type for YAML Version 1.1 yaml.org, working draft 2005-01-18
  7. Value Key Language-Independent Type for YAML Version 1.1 yaml.org, working draft 2005-01-18
  8. The JavaScript Object Notation (JSON) Data Interchange Format RFC Editor (IETF), RFC 8259
  9. eemeli/yaml at tag v2.9.0 Eemeli Aro, source repository
  10. yaml LICENSE at tag v2.9.0 Eemeli Aro, ISC licence
  11. yaml documentation Eemeli Aro
  12. YAML - Wikipedia Wikipedia
  13. Octal - Wikipedia Wikipedia
  14. Sexagesimal - Wikipedia Wikipedia
  15. BigInt - JavaScript MDN Web Docs (Mozilla)
  16. JSON.parse() - JavaScript MDN Web Docs (Mozilla)