How to Use This Tool
Paste JSON and get YAML with anything ambiguous quoted. The list underneath shows every value that would have changed meaning without the quotes.
The Norway problem
YAML 1.1 resolves a set of unquoted words to booleans, and the set is much larger than
true and false:
y Y yes Yes YES n N no No NO true false on On ON off Off OFF
So a list of ISO country codes containing NO parses as a list containing
false. Sweden and Denmark are fine; Norway is a boolean. The same applies to
y for anything abbreviated and to ON and OFF in configuration.
YAML 1.2 narrowed this to true and false only, and a great deal of tooling
still implements the 1.1 behaviour — including parsers used in widely deployed systems. You cannot
rely on which version will read your file, so quoting is the only portable answer.
The other three
- Version numbers.
1.10unquoted is the number 1.1, and the trailing zero is gone. Anything comparing versions as strings then behaves oddly. - Leading zeros.
022is octal 18 in YAML 1.1. Build numbers, zero-padded identifiers and some postcodes all hit this. - Colons in values.
12:30is sexagesimal 750 in YAML 1.1 — twelve sixties plus thirty. Times, ports and MAC addresses are all at risk.
All four failures share a shape: the file parses, no error is raised, and the value is a different type than intended. Nothing downstream has any reason to suspect it.
Indentation rules that catch people
- Spaces only. A tab character is a syntax error in YAML, and editors insert them silently.
- List indentation is optional. A sequence under a key may be indented or flush with the key, and both are valid and identical. Kubernetes examples use both, which is why it looks inconsistent.
- Indentation must be consistent within a block but not across the file, which makes mixed styles legal and unreadable.
Multi-line strings
JSON escapes newlines as \n. YAML has block scalars instead, and the two markers differ
in one important way:
|keeps the newlines. Use it for scripts, certificates and anything where line breaks matter.>folds them into spaces. Use it for prose you want to wrap in the file.
Getting these the wrong way round turns a shell script into one long line, or a paragraph into a column
of fragments. This tool uses | for anything containing a newline, which is the safe
default.
