Hunt
Skip to content

YAML to JSON

Paste YAML, from a Kubernetes manifest, a CI pipeline or Docker Compose, to get the JSON your program will actually see. Anchors, aliases and merge keys are resolved, numbers keep every digit, and values that YAML 1.1 and 1.2 parsers read differently, such as no, on or 0755, are pointed out. Nothing is uploaded.

Runs in your browser

YAML

Paste YAML or press Sample

JSON

JSON will appear here

YAML 1.1 or 1.2?

The two versions of YAML read some unquoted values differently. YAML 1.2 (the default here, and in most JavaScript, Go and Rust parsers) reads no, on and yes as text and 0755 as 755. YAML 1.1, still used by PyYAML, Ruby and many CI systems, reads them as booleans and as the octal number 493. Choose the version your program's parser uses; the notes list every value the other version would read differently.

How to use the YAML to JSON

  1. Paste YAML, or press Sample.
  2. Choose the YAML version your parser uses.
  3. Read the notes for values that might not mean what you expect.
  4. Copy or download the JSON.

Examples

Docker Compose service

Input
services:
  web:
    image: nginx:1.27
    ports:
      - "8080:80"
    environment:
      DEBUG: "false"
      WORKERS: 4
Output
{
"services": {
"web": {
"image": "nginx:1.27",
"ports": [
"8080:80"
],
"environment": {
"DEBUG": "false",
"WORKERS": 4
}
}
}
}

Values YAML 1.1 reads differently

Input
country: NO
mode: 0755
Output
{
"country": false,
"mode": 493
}

With YAML 1.2, the same input gives "NO" and 755. Quote values like these to make them mean the same everywhere.

Merge keys

Input
defaults: &defaults
  retries: 3
  timeout: 30
production:
  <<: *defaults
  timeout: 60
Output
{
"defaults": {
"retries": 3,
"timeout": 30
},
"production": {
"retries": 3,
"timeout": 60
}
}

production gets retries from defaults, and its own timeout overrides the merged one.

Anchors, aliases and merge keys

&name marks a value, *name repeats it, and <<: *name merges a mapping's keys into another, with the mapping's own keys taking priority. JSON has none of these, so the values are copied in full, as your program would see them.

Options

YAML version
1.2 (the default) or 1.1, to match your parser. Merge keys are supported in both.
Indent
2 spaces, 4 spaces or minified JSON.

Limitations

  • Custom tags (such as !Ref in AWS CloudFormation) are read as plain values, without their tag.
  • YAML 1.1 timestamps are kept as the text written, because JSON has no date type.
  • .inf and .nan become null, because JSON can't represent them.

Frequently asked questions

Is my YAML uploaded?

No. The conversion runs in your browser; nothing you paste is sent anywhere.

Why did my version number change?

Unquoted, version: 1.10 is a number, which most programs store as 1.1. The JSON keeps the digits as written, but quote version numbers in YAML ("1.10") to keep them as text.

Can it convert several documents?

Yes. A file with several documents separated by --- becomes a JSON array with one element per document.

How do I convert JSON to YAML?

Use the JSON to YAML converter.