Skip to content

YAML to JSON Format Conversion

Parses one YAML document with the yaml library (YAML 1.2 core schema) and outputs it as indented JSON. Comments are dropped, anchors and aliases are expanded, and values like yes or 2024-01-01 stay strings.

Sending settings written in YAML to an API or JSON Schema validator that only accepts JSON.

When to use it

  • Sending settings written in YAML to an API or JSON Schema validator that only accepts JSON.
  • Checking how a CI or Kubernetes file is actually typed, e.g. whether a version is a string or a number.

How to use

  1. Paste a single YAML document or load a .yaml/.yml file.
  2. If an error appears, check indentation, duplicate keys and --- separators at the reported line.
  3. Review strings versus numbers in the JSON output, then copy it.

YAML input

# deployment settings
service: billing-api
replicas: 2
version: "1.10"
enabled: yes
ports:
  - 80
  - 443
env:
  LOG_LEVEL: info

JSON

{
  "service": "billing-api",
  "replicas": 2,
  "version": "1.10",
  "enabled": "yes",
  "ports": [
    80,
    443
  ],
  "env": {
    "LOG_LEVEL": "info"
  }
}

Details and limitations

Parsing runs in the browser. Output is always 2-space JSON; there is no minify option.

YAML 1.2 rules apply: yes/no/on/off are strings, not booleans, and unquoted dates stay strings. 0o17 is octal (15).

Merge keys (<<: *anchor) are not merged; they appear as a literal "<<" key. Duplicate keys in one mapping are an error.

Integers beyond 2^53 lose precision in JSON. Quote long IDs in the YAML.

FAQ

Can it convert a file with several documents separated by ---?

No. Multiple documents cause the error "Source contains multiple documents". Paste one document at a time. A single leading --- is fine.

Why is enabled: yes a string in the JSON?

The parser follows YAML 1.2, where only true and false are booleans. Write true/false if you need a JSON boolean.

Are anchors and aliases supported?

Yes. An alias like *base is replaced by a copy of the anchored value. The YAML 1.1 merge key << is not applied, though.

Specifications and references