How YAML values are typed
YAML writes everything as plain text and decides the type from how the text looks. This converter follows the YAML 1.2 core rules:
true,TrueandTRUEare booleans.yes,no,onandoffare ordinary text, socountry: nogives"country": "no".null,~and an empty value are null.42,-3.5,1e3and0x1Fare numbers (42, -3.5, 1000 and 31), and0o14is the octal number 12.1.10is the number 1.1, not the text 1.10. If it is a version, write"1.10"in quotes in the YAML.2001-12-14and12:30:45stay text, and so does anything in quotes..infand.nanbecome the text Infinity and NaN, with a warning, because JSON has no such numbers.
Whole numbers with more than 15 digits can lose their last digits when read, and a warning appears when the file has some. Put such IDs in quotes.
YAML 1.1 and 1.2: when the same file reads differently
YAML 1.2, published in 2009, removed several guesses that YAML 1.1 made. Many tools, including PyYAML and Ruby's YAML library, still follow the 1.1 rules, where no is false, on is true, 014 is an octal number and 12:30:45 is a base 60 number. The same file can give different data depending on the reader.
This page shows what a 1.2 reader sees. If your tool is a 1.1 reader, check every value that is yes, no, on, off, a time or has a leading zero, and put it in quotes in the YAML. A quoted value is text in every version of YAML.
Anchors, merge keys and several documents
Anchors let YAML define a block once and reuse it. defaults: &defaults marks a block, *defaults repeats it, and <<: *defaults merges it into another mapping, where keys written next to it win. JSON has no references, so each use becomes a full copy. In the example on this page both people get team and active from the defaults, and Ben's own team: Engineering replaces the default.
Copies can make the JSON much larger than the YAML. An anchor can be reused as often as you like, so a Docker Compose file that merges the same block into thousands of services converts. A file whose aliases would add more than about two million items (keys, values and lists) to what the file shows is refused with a message. Nested aliases can do that from a few lines, and the refusal protects your browser tab. An anchor that contains its own alias cannot be converted, and a merge key has to point to a mapping or a list of mappings.
A YAML file can hold several documents separated by ---, as Kubernetes files often do. They become a JSON list with one item per document, and a note says how many.
What does not carry over to JSON
- Comments are dropped.
- Keys that are not text, such as
1: oneortrue: yes, become text keys: "1" and "true". - Tags are not kept. A
!!setbecomes a list, a custom tag such as!custom valueleaves just its value, and binary data written with!!binarybecomes a list of byte numbers. - Multi line text written with
|or>becomes one string with line breaks, as YAML defines them. The final line break is kept unless you write|-or>-.