Guide
YAML to JSON and the type surprises in between
By Logappradeep · ServiceNow developer
Many tools only understand JSON: jq, JSON Schema validators, REST APIs, and most programming language standard libraries. If your data lives in a Kubernetes manifest, a Compose file, or a CI pipeline written in YAML, converting it to JSON lets you query, validate, or send it anywhere. Conversion also reveals how a YAML parser actually interprets your file, which is often not what the author intended.
How YAML decides on types
Unquoted YAML values are typed by pattern: anything that looks like a number becomes a number, true and false become booleans, and null or ~ becomes null. That convenience causes real bugs. Converting this input:
version: 1.10
zip: 012345
port: 08
released: 2024-01-15
country: no
produces:
{
"version": 1.1,
"zip": 12345,
"port": 8,
"released": "2024-01-15T00:00:00.000Z",
"country": "no"
}
1.10became1.1because it was read as a decimal number. Quote version numbers.- The ZIP code lost its leading zero. Quote postal codes, phone numbers, and IDs.
- The date became a full timestamp because unquoted dates are parsed as date values.
nostayed a string here, because this parser follows the YAML 1.2 core schema. Older YAML 1.1 parsers, still common in some ecosystems, readno,yes,on, andoffas booleans, which is the infamous "Norway problem" for the country code NO. Quote such values so every parser agrees.
Other YAML features and how they convert
- Anchors and aliases (
&defaultsand*defaults) are expanded, so the JSON contains full copies of the shared block. - Comments are dropped since JSON has no place for them.
- Block scalars using
|or>become ordinary strings with\nline breaks. - Multiple documents separated by
---, common in Kubernetes files, are converted into a JSON array with one element per document.
Errors you might see
YAML is whitespace-sensitive. Tabs used for indentation, inconsistent indentation within a list, a missing space after a colon, and unquoted strings containing : or a leading * are the usual culprits. The error panel shows the parser's message with a line and column to guide you.
Parsing happens in your browser, so configuration details and internal hostnames stay on your machine.