harmmy

What quietly changes when YAML becomes JSON

Comments, anchors and YAML 1.1 booleans vanish or shift during conversion. A practical map of what survives, what breaks, and how to catch it early.

2026-12-04

Comments and anchors do not survive

YAML is written for humans: it allows # comments, & anchors to name a block, * aliases to reuse it, and --- to separate several documents in one file. JSON has no syntax for any of these. Converting strips every comment, resolves each alias into a full copy, and drops the anchor name. A `base: &base {timeout: 30}` used in two places leaves as two separate JSON objects, each carrying `"timeout": 30`.

That expansion is rarely wrong, but it changes maintenance. Edit the JSON copies in three places and they drift apart until the next conversion; converting back cannot know they once shared an anchor. Multiple documents are worse: this converter parses a single document, so a file with more than one --- is rejected instead of quietly keeping the first. Split the file or convert each document separately.

yes, no, on and off can flip to booleans

YAML 1.1 treats yes, no, on, off, y and n as booleans; YAML 1.2 only accepts true and false. The parser in this tool follows 1.2 behavior, but Ansible, some CI templates and older Kubernetes libraries still run on 1.1. A config that says `enabled: no` can therefore arrive as false in one pipeline and as the string "no" in another.

The classic failure is an `on:` key inside a mapping. Under 1.1 the key on is a boolean, so it becomes "true", and the JSON side suddenly has different keys or a duplicate. Quote anything that must stay textual — "no", "on", "1.0" — and run the round trip in the exact runtime that will consume the file, not just in your own shell.

Numbers and dates lose their written form

JSON has numbers and strings, nothing else. An unquoted 2026-12-04 is a date to YAML 1.1 parsers and can come back as a timestamp with a time and offset; the 1.2 core parser in this tool keeps it as text, but the service that reads the file may not. A bare 1.0 becomes the number 1 and prints back as 1, and 0123 is octal 83 in 1.1 but decimal 123 in 1.2. JSON.stringify reprints numbers in its own form, so the original width and leading zeros are gone.

The fix is quoting at the source: keep version numbers, phone numbers, IDs and dates in quotes so both formats carry them as strings. For very large values, remember that JSON numbers are IEEE 754 doubles; anything beyond 2^53 loses digits before your code sees it. Store such fields as strings in both directions and treat the conversion as a display step, not a normalization step.

Indentation is syntax, and tabs are not allowed

YAML takes spaces only. A tab used for indentation is a parse error, and "line 7, column 3" is all the explanation you get. The more common failure is a child block indented four spaces while its siblings use two: the parser does not see a typo, it sees a new, deeper mapping, and the error surfaces a few lines later as an indentation complaint at line 9, column 5. Duplicate keys are the second silent failure — many parsers keep the last value, some reject the document, and a merge can drop the first block without a warning.

Plain scalars are context-sensitive too. A value containing a colon plus a space, or one that starts with #, must be quoted or the parser reads a mapping or a comment. URLs and times such as 12:30 are safe unquoted, but `key: value: more` is not. In a list item, `- env: prod # staging` loses the rest to a comment, and the error then points at a later line instead of the real one.

JSON rejects what YAML forgives

Going the other way, JSON is stricter than most people expect: no comments, no trailing commas, no single-quoted strings, no unquoted keys, no NaN or Infinity literals. A file that was valid JSON5, or a fragment edited by hand in YAML style, fails with a position in the message; this tool surfaces the line and column rather than a generic "invalid JSON".

The realistic failure is a config edited at 1 a.m.: a trailing comma after the last array element, or 'production' in single quotes. With a line number it is a quick fix. Harder are duplicate keys: JSON.parse keeps the last one, so a file with two "port" entries loads cleanly and quietly uses the wrong value. A JSON Formatter that re-emits sorted, indented output makes duplicates visible before they cause downtime.

Validate, convert, then validate again

Treat the converter as one step in a pipeline, not the record of truth. Before committing a CI, Kubernetes or OpenAPI change, paste it into YAML ↔ JSON Converter to confirm it parses at all; an error with a line and column costs far less than a failed forty-minute pipeline. After conversion, run the same schema validation you use in production — JSON Schema, kubeconform or the OpenAPI linter — because a successful parse proves syntax, not the contract.

Keep the source of truth in one format and generate the other; do not edit both. For tabular data, use CSV to JSON and JSON to CSV instead of hand-building objects. And for anything containing tokens, passwords or private endpoints, prefer a page that processes locally in the browser and never uploads the text — as this site's tools do. If a paste must go somewhere else, rotate the secret afterwards, because a config that parsed correctly can still be logged in full.

Related tools

What quietly changes when YAML becomes JSON | harmmy