Convert between YAML formatting and JSON objects.
YAML and JSON are often seen as competing formats for configuration files, but they are mathematically related: YAML version 1.2 was explicitly designed as a strict superset of JSON.
This means that every valid JSON file is automatically a valid YAML file. A fully compliant YAML parser should be able to read standard JSON syntax perfectly.
If a YAML parser can natively read JSON, why do we need tools to convert between them?
Because the relationship is strictly one-way. JSON parsers cannot read YAML-specific features like unquoted strings, comments, anchors (&id), or multi-line block scalars (|).
If an application environment only provides a JSON parser (like a web browser with native JSON.parse()), you must "compile" your YAML down to JSON before feeding it into the application.
Because YAML contains structural features that simply do not exist in the JSON specification, converting YAML to JSON is an inherently lossy process.
Most notably, JSON does not support comments. Any explanatory comments written in your YAML file will be permanently deleted when converted to JSON. Additionally, YAML anchors and aliases (which allow you to DRY up your config by referencing a block multiple times) will be fully resolved and expanded, causing the JSON file size to inflate significantly compared to the original YAML.
Which of the following statements about the relationship between YAML and JSON is true?