YAML to JSON
YAML is not JSON with comments. `NO` is false, `on` is true, and Norway's country code will disappear into a boolean if you don't quote it.
YAML is not JSON with comments. NO is false, on is true, and Norway's country code will disappear into a boolean if you don't quote it.
Paste YAML. Read the JSON. If a value you typed as a string became true, false, or null, quote it and convert again.
How to use it
- Quote anything that looks like a boolean, null, or number:
NO,Yes,off,on,null,1.0,08. Country codes and IDs go in quotes. Always. - Comments (
# …) are dropped. JSON has nowhere to put them. If the comment was the point, don't convert. - Anchors and aliases (
&id,*id) get inlined. The duplicate is real data in JSON, not a reference. - Tabs are illegal. Indent with spaces. A tab looks fine in the editor and blows up the parse.
When it breaks
- Duplicate keys: last one wins, quietly. The JSON will not show you the first.
- Multiline (
|vs>): one keeps newlines, one folds them. Pick on purpose. - Version 1.1 vs 1.2 boolean rules differ. If
NOsurvived, you got 1.2 or a quoted string. If it died, you got 1.1.
YAML Input
JSON Output
Features
- Parses YAML then JSON.stringify: comments never survive
- Anchors and aliases are inlined (duplicated values, no &/* left)
- Country code NO (Norway) becomes boolean false unless quoted
- Multi-document --- files become a JSON array of documents
Common Use Cases
- See why a Helm values country: NO became false in JSON
- Confirm comments you needed for humans are gone after convert
- Expand YAML anchors before an API that only speaks JSON
- Turn a multi-doc Kubernetes dump into a JSON array
YAML is not JSON with comments
YAML is not JSON with comments. NO is false, on is true, and Norway's country code will disappear into a boolean if you don't quote it.
Paste YAML. Read the JSON. If a value you typed as a string became true, false, or null, quote it and convert again.
Quote anything that looks like a boolean, null, or number: NO, Yes, off, on, null, 1.0, 08. Country codes and IDs go in quotes. Always. Comments (# …) are dropped. JSON has nowhere to put them. If the comment was the point, don't convert.
Anchors and aliases (&id, *id) get inlined. The duplicate is real data in JSON, not a reference. Tabs are illegal. Indent with spaces. A tab looks fine in the editor and blows up the parse.
Examples
country: NO
# JSON: {"country": false}country: "NO"
# JSON: {"country": "NO"}port: 8080 # listen port
# JSON has no commentdefaults: &def
retries: 3
svc:
<<: *def
# JSON: svc.retries is 3, no &defFrequently Asked Questions
YAML is not JSON with comments. NO is false, on is true, and Norway's country code will disappear into a boolean if you don't quote it. Quote anything that looks like a boolean, null, or number: NO, Yes, off, on, null, 1.0, 08. Country codes and IDs go in quotes. Always. If a value you typed as a string became true, false, or null, quote it and convert again.
Comments (# …) are dropped. JSON has nowhere to put them. If the comment was the point, don't convert. Anchors and aliases (&id, *id) get inlined. The duplicate is real data in JSON, not a reference.
Tabs are illegal. Indent with spaces. A tab looks fine in the editor and blows up the parse.
Duplicate keys: last one wins, quietly. The JSON will not show you the first. Multiline (| vs >): one keeps newlines, one folds them. Pick on purpose. Version 1.1 vs 1.2 boolean rules differ. If NO survived, you got 1.2 or a quoted string. If it died, you got 1.1.
Tips
- Quote any scalar that looks like a boolean, null, or number but is an identifier (NO, on, 01).
- Do not expect comments or anchors to survive a round-trip.
- If JSON output shows false for a country field, that is Norway, not a missing value.