logoalt Hacker News

Centigonal12/09/20242 repliesview on HN

I'm confused about your point about YAML being "strict superset of JSON" leading to being able to convert YAML to JSON.

If YAML is a strict superset, wouldn't that mean that YAML must have at least one feature that is not part of JSON? Wouldn't that make it impossible to define all YAML files as valid JSON?


Replies

Dylan1680712/09/2024

They all turn into the same data types in the end. You can import a YAML and output a JSON.

For a feature like references, you'd have to do the annoying thing and duplicate that section of the file.

For a feature like unquoted strings or extra commas, you just quote the strings or remove the commas.

The various YAML features are in between and mostly close to the latter.

AdieuToLogic12/10/2024

> If YAML is a strict superset, wouldn't that mean that YAML must have at least one feature that is not part of JSON?

Yes. One of the features YAML supports is the widely documented format we are all familiar with.

However, being a "strict superset of JSON" also means a conformant YAML implementation can load a "pure" JSON resource without issue. The converse is not generally possible as JSON cannot express what YAML can, such as octothorpe ('#') comments.

HTH

EDIT: see also https://news.ycombinator.com/context?id=42361994