Where the formats differ

Every JSON document maps to YAML, but not every YAML document maps back to JSON without loss. YAML has anchors, aliases, multiple documents and tags; JSON has none of those. The conversion here is one-way and produces plain YAML without anchors.

  • Strings containing : or # are quoted to avoid being parsed as mappings or comments.
  • Multiline strings use literal block scalars with chomping indicators so leading and trailing newlines are preserved.
  • Booleans stay true/false; YAML 1.1 also accepts yes/no, which causes surprises when read by older parsers.
  • Null becomes null, not ~, for clarity.

A conversion example

yaml
service:
  name: api
  replicas: 3
  env:
    - name: LOG_LEVEL
      value: info

If you paste the YAML back into a strict JSON parser it will fail; use a YAML parser. The two formats are not interchangeable at the syntax level.