Is YAML a Superset of JSON?
Yes, YAML 1.2 is a superset of JSON. This means all valid JSON is also valid YAML. You can paste any JSON into a YAML parser and it will work. YAML 1.1 had minor incompatibilities, but YAML 1.2 (released 2009) achieved full JSON compatibility. Try it with our free online converter.
What "Superset" Means
If YAML is a superset of JSON, then:
- Every valid JSON document is valid YAML
- YAML parsers can read JSON files directly
- JSON syntax works inside YAML files
- YAML has additional features JSON doesn't
Proof: JSON Works in YAML Parsers
This JSON:
{
"name": "John",
"age": 30,
"hobbies": ["reading", "gaming"]
}
Is valid YAML (paste it directly):
# This is valid YAML!
{"name": "John", "age": 30, "hobbies": ["reading", "gaming"]}
Python proof:
import yaml
import json
json_string = '{"name": "John", "age": 30}'
# Both produce the same result
json_result = json.loads(json_string)
yaml_result = yaml.safe_load(json_string)
print(json_result == yaml_result) # True!
Edge Cases and YAML Versions
| YAML Version | JSON Compatible? | Notes |
|---|---|---|
| YAML 1.2 | ✅ Full | Official superset since 2009 |
| YAML 1.1 | ⚠️ Mostly | Some edge cases differ |
YAML 1.1 Gotchas
# YAML 1.1 might interpret these differently:
yes: true # "yes" becomes boolean true
no: false # "no" becomes boolean false
on: true # "on" becomes boolean true
off: false # "off" becomes boolean false
# In JSON these would be string keys:
{"yes": "value"} → key is the STRING "yes"
# YAML 1.2 fixed this - now matches JSON behavior
yaml.safe_load(), js-yaml, etc.) for guaranteed JSON compatibility.
Mixing JSON and YAML Syntax
Since JSON is valid YAML, you can mix both styles in one file:
# YAML style with JSON inline
name: John Doe
age: 30
# JSON-style inline arrays (valid YAML!)
hobbies: ["reading", "gaming", "hiking"]
# JSON-style inline objects
address: {"city": "NYC", "zip": "10001"}
# YAML-style same data
address_yaml:
city: NYC
zip: "10001"
When to Use Each Style
- YAML style: Better for long, nested configs
- JSON inline: Better for short arrays/objects
- Mixed: Common in real-world configs
Frequently Asked Questions
Is YAML a superset of JSON?
Yes, YAML 1.2 is officially a superset of JSON. This means all valid JSON is also valid YAML. You can paste any JSON into a YAML parser and it will work. YAML 1.1 had some incompatibilities, but YAML 1.2 (released 2009) fixed them for full JSON compatibility.
Is JSON valid YAML?
Yes, any valid JSON document is also a valid YAML document. YAML parsers can read JSON files directly. This means you can rename a .json file to .yaml and most YAML tools will parse it correctly.
Can you write JSON in a YAML file?
Yes, you can use JSON syntax inside YAML files. Many
developers mix both: using YAML's indentation style for most content but
JSON's inline syntax for compact arrays and objects:
items: [1, 2, 3] or config: {"key": "value"}.
Are there edge cases where JSON doesn't work in YAML?
With YAML 1.2, there are no incompatibilities for standard JSON. However, YAML 1.1 parsers may have issues with certain strings (like 'yes', 'no', 'on', 'off') being interpreted as booleans. Always use a YAML 1.2 compliant parser for perfect JSON compatibility.
Need to convert between formats?
Use our free online converter for instant JSON ↔ YAML conversion.
Open Converter Tool →