Files
static-site-pipeline/hugo/content/posts/2024-03-14-yaml-superset-json.md
Smaug123 fc9bcfb85a YAML
2024-03-14 00:26:18 +00:00

1003 B

lastmod, author, date, title, summary, categories
lastmod author date title summary categories
2024-04-14T00:12:00.0000000+00:00 patrick 2024-03-14T00:12:00.0000000+00:00 YAML is not a superset of JSON All the reasons I know for why YAML is not a superset of JSON.
programming

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.

>>> 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.

>>> 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': [{}, {}]}