YAML is not a superset of JSON

I keep forgetting, so here we go. Please let me know if you have any others!

Treatment of e.g. 1e2

JSON treats the value 1e2 a number, of course, because it’s not in quote marks. YAML fails to parse it as a number so silently falls back to treating it as a string.

1
2
3
4
5
6
7
8
>>> import yaml
>>> import json

>>> yaml.safe_load('{"a": 1e2}')
{'a': '1e2'}

>>> json.loads('{"a": 1e2}')
{'a': 100.0}

Tabs as indentation

YAML does not permit tabs to be used as indentation.

1
2
3
4
5
6
>>> yaml.load ('{\n  "list": [\n    {},\n\t{}\n    ]\n}')
# yaml.scanner.ScannerError: while scanning for the next token
# found character '\t' that cannot start any token

>>> json.loads('{\n  "list": [\n    {},\n\t{}\n    ]\n}')
{'list': [{}, {}]}