7 YAML gotchas to avoid when converting from JSON

The Norway problem, vanishing leading zeros, rounded IDs and other surprises that appear when JSON becomes YAML, with the fix for each.

Guides By Convert JSON to YAML Team

7 YAML gotchas to avoid when converting from JSON

JSON is explicit: a string is always in double quotes. YAML guesses the type of unquoted values, and that is where most conversion bugs come from. These are the seven we see most often.

1. The Norway problem

In YAML 1.1, the unquoted words yes, no, on, off, y and n are booleans. A list of country codes that includes NO for Norway can turn into false.

# Wrong: parsed as a boolean by YAML 1.1 parsers
country: no

# Right
country: 'no'

Fix: keep the “YAML 1.1 safe” option on so these strings are quoted.

2. Leading zeros disappear

The JSON string "007" must stay a string. Unquoted, some parsers read it as the number 7, others as an octal value.

Fix: quote numeric-looking strings. The converter does this automatically.

3. Version numbers become floats

"1.10" and "1.1" are different versions, but as YAML numbers they are equal. This one breaks Docker tags, Python versions and Helm chart values.

version: '1.10'

4. Big integers get rounded

JavaScript stores numbers as 64-bit floats, so integers above 9,007,199,254,740,991 lose precision. A database ID such as 9223372036854775807 can come out as 9223372036854775808. Our converter preserves these digit for digit.

5. Special characters in strings

A value containing a colon followed by a space, or a space followed by #, changes meaning when unquoted: the first starts a nested mapping and the second starts a comment.

note: 'key: value # not a comment'

6. Multi-line strings

JSON escapes line breaks as \n. In YAML a block scalar is far easier to read and edit:

script: |
  npm ci
  npm test

7. Null, empty string and missing are different

null, "" and an absent key mean three different things to most applications. YAML writes them as null (or ~), '' and nothing at all. Decide deliberately whether to keep nulls; the “Drop nulls” option removes them when your schema treats null and missing the same way.

Checklist

  • Quote strings that look like booleans, numbers, dates or null.
  • Preserve big integers.
  • Use block scalars for multi-line text.
  • Validate the result with the tool that will read it, such as kubectl apply --dry-run=client.

Paste your JSON into the converter and try the “Tricky values” sample to see each of these cases handled.

← Blog