Most conversion problems announce themselves: a file will not parse, a tool shows an error, you fix the syntax and move on. YAML to JSON mistakes are quieter. The file parses, the JSON is valid, and the data inside is wrong in ways you notice only later: a setting in the wrong place, a shared value no longer shared.
This guide covers the four traps behind that quiet damage: an indentation slip that moves a key under the wrong parent, anchors that expand instead of staying referenced, timestamps that change shape, and duplicate keys that stop the conversion. All four show up when you convert with the free YAML to JSON Converter on Ovatly, because that tool converts what your YAML actually says, not what you meant it to say.
Contents
- Quick answer
- Why these mistakes survive conversion
- Mistake 1: one indent level moves a key to the wrong parent
- Mistake 2: anchors come out expanded, not referenced
- Mistake 3: timestamps quietly become ISO strings
- Mistake 4: duplicate keys stop the conversion
- How to convert, step by step
- Worked example: the credentials block that moved
- Limitations and honest tradeoffs
- Common mistakes
- FAQs
- Conclusion
- References
Quick answer
Check indentation first: in YAML, the spaces at the start of a line decide which parent a key belongs to, and one shifted level produces valid JSON with keys in the wrong place. Expect anchors expanded into full values, because JSON has no reference syntax, and values that look like dates to become ISO date-time strings. If conversion fails on a file that looks fine, look for a repeated key: duplicate keys are an error. Paste your file into the YAML to JSON Converter, convert, and read the output structure before trusting it.
Why these mistakes survive conversion
The converter is built on js-yaml and works in both directions, YAML to JSON and JSON to YAML. It reads your file the way the YAML specification says to read it, with YAML 1.2 core features supported. That faithfulness is why mistakes survive: the tool cannot know a key was supposed to sit one level deeper, so it converts the structure it finds.
JSON is also a smaller language than YAML: no anchors, no comments, no date type. Anything that depends on those features must change shape during conversion, in the ways the next sections describe.
Mistake 1: one indent level moves a key to the wrong parent
In JSON, braces state the structure out loud. In YAML, structure is indentation, so a line starting two spaces too early belongs to a different parent, and nothing about the line looks wrong. The parser accepts it, and the first symptom appears somewhere else: a program ignoring a setting, or reading a null where you wrote a whole block.
The classic version is a nested block whose contents were pasted at the parent level. The header promises a group, the group is empty, and the values sit beside it as siblings. The worked example below shows exactly that shape.
Two habits prevent it: use one indent step, usually two spaces, everywhere in the file; and after converting, check that each key sits under the parent you intended, especially pasted blocks.
Mistake 2: anchors come out expanded, not referenced
Anchors are YAML's way of writing a value once and reusing it. You mark a value with an anchor such as &defaults; later lines pull it in with *defaults or merge it with the << key.
JSON has nothing like this, so the converter expands every anchor into the full values. A block that was written once appears in full at every place that referenced it. The output is correct and complete, but two things change: the file gets bigger, sometimes much bigger, and the connection between the copies is gone. Edit one expanded copy later and the others do not follow, because JSON never linked them.
Mistake 3: timestamps quietly become ISO strings
YAML recognises dates. A plain value like 2026-11-27 is not read as text; it is read as a timestamp. When that value is converted, timestamps become ISO date-time strings, so the JSON carries 2026-11-27T00:00:00.000Z where your file showed a short date.
The trap is the surprise: a string comparison fails, or a receiving system expecting the short form rejects it. If a value must stay exactly the text you typed, quote it in the YAML, as in released: "2026-11-27", and it will convert as a plain string.
Mistake 4: duplicate keys stop the conversion
Write the same key twice in one mapping and the conversion fails with an error: duplicate keys are never silently overwritten, so the second value does not quietly replace the first.
This one at least announces itself, unlike the other three. In a hand-maintained file, a duplicate usually means a copy and paste slip or two edits that were never merged, and the error does you a favour by stopping instead of guessing. Find both occurrences, decide which is real, delete the other, convert again.
How to convert, step by step
- Open the YAML to JSON Converter and paste your YAML into the input.
- Convert. A syntax problem or duplicate key produces an error instead of output; fix the file and try again.
- Read the JSON structure before copying it anywhere: expand the top levels and confirm keys sit under the parents you intended.
- Check the known shape changes: anchors expanded, timestamps in ISO form.
- Copy or download the result, and keep the YAML original for future edits.
Worked example: the credentials block that moved
Here is a small config with the trap in it:
database:
host: db.local
credentials:
user: admin
password: secret
The intention was for user and password to live inside credentials. But they sit at the same indent level as credentials itself, so YAML reads them as part of database, and credentials, having nothing under it, is empty. The converted JSON says exactly that:
{
"database": {
"host": "db.local",
"credentials": null,
"user": "admin",
"password": "secret"
}
}
Valid JSON, wrong data: a program looking for database.credentials.user finds nothing. The fix is two spaces on each of the last two lines:
database:
host: db.local
credentials:
user: admin
password: secret
Convert again and user and password sit inside credentials, where they belonged all along.
Limitations and honest tradeoffs
The converter handles YAML 1.2 core features, which covers most config files, but exotic YAML tricks outside that core may not survive the trip. Comments never survive: JSON has no comments, so every explanation in the YAML is dropped. Key order is preserved as written.
Conversion is one snapshot in time: if the source YAML changes, convert again instead of editing the JSON by hand.
Common mistakes
- Trusting a successful conversion. Success means the YAML parsed, not that the structure matches your intention. Read the output.
- Pasting blocks at the wrong indent level, the most common cause of keys landing under the wrong parent.
- Expecting anchors to survive. They expand. Edit the YAML original, not one expanded copy in the JSON.
- Leaving dates unquoted. They become ISO date-time strings. Quote any date that must stay a short plain string.
- Deleting the wrong duplicate. When the error stops you, check which occurrence is current before removing one.
FAQs
Why is my JSON valid but the keys are in the wrong place? Because indentation defines nesting in YAML. If a key sits one level too shallow or too deep, the parser reads it under a different parent, and the converter faithfully converts that structure. The JSON is a correct conversion of a wrongly structured file.
What happens to YAML anchors when I convert to JSON? They are expanded. JSON has no references, so every place that pointed at an anchor receives the full values inline. The data is complete, but editing one copy later no longer updates the others.
Why did my date turn into a long string with a T in the middle? YAML reads a value like 2026-11-27 as a timestamp, and timestamps become ISO date-time strings in JSON, such as 2026-11-27T00:00:00.000Z. Quote the value in the YAML if you need it to stay a plain short string.
Why does the converter refuse a file that uses the same key twice? Duplicate keys are treated as an error, never silently overwritten. In a hand-edited file a repeated key usually means a copy and paste slip, and keeping only the second value would hide it.
Is my file uploaded to a server for conversion? No. The converter runs js-yaml in your browser and the conversion happens on your device. Nothing is sent to Ovatly or anywhere else, so config files with internal settings stay private.
Conclusion
Converting YAML to JSON is safe exactly when you read the result: check indentation put every key under the parent you meant, expect anchors as expanded values and dates as ISO strings, and let duplicate key errors point you at editing slips. The YAML to JSON Converter does the mechanical work in your browser; the two minutes of structural checking are yours. For docker-compose files, our companion guide on converting docker-compose YAML settings into JSON walks through that specific shape. For more guides in this series, see our Data and JSON Tools guides.
References
- The YAML specification, on mapping structure and indentation: https://yaml.org/spec/1.2.2/
- js-yaml, the parser the converter is built on: https://github.com/nodeca/js-yaml