Tutorial · YAML → JSON · 3 min read

How to Convert YAML to JSON

Turn a Kubernetes manifest, Compose file or any YAML document into equivalent JSON in your browser, and learn where the two formats quietly differ.

YAML is the format people write; JSON is the format tools consume. Converting lets you feed a manifest to an API that only accepts JSON, inspect exactly how a YAML parser understood your indentation, or debug a value that YAML quietly typed as a number or boolean.

What you'll learn

  • Convert YAML to indented JSON as you type
  • Spot YAML type surprises such as 1.10 becoming 1.1 or a port becoming a number
  • Convert multi-document files (--- separated) in one go

Step by step

  1. Paste the YAML

    Open YAML to JSON and paste the document. The conversion runs on every keystroke, so you can fix indentation errors live.

  2. Read the JSON output

    Mappings become objects and sequences become arrays. Scalars keep the type the YAML parser inferred, which is the most common source of surprises.

    name: Ada
    roles:
      - admin
      - user
    
    →
    
    {
      "name": "Ada",
      "roles": ["admin", "user"]
    }
  3. Check inferred types

    Unquoted 8080 becomes a number and 1.10 becomes 1.1. This converter follows YAML 1.2, so yes, no, on and off stay strings, but older YAML 1.1 parsers such as PyYAML turn them into booleans. Quote anything that must stay a string.

  4. Copy the result

    Use Copy Output. A file with several --- separated documents comes out as a JSON array with one element per document.

Open the tool with this example Runs in your browser. Nothing you paste is uploaded.

Common problems

bad indentation of a mapping entry

A line is indented by a different number of spaces than its siblings, or a tab crept in. YAML requires spaces and consistent indentation within a block.

A port or version came out as a number

YAML types 8080 as a number and 1.10 as 1.1. Quote them ("8080", "1.10") if the consuming system expects strings.

yes and no became true and false somewhere else

That system uses a YAML 1.1 parser. This converter keeps them as strings, so quote yes, no, on and off in the source file to get the same result everywhere.

FAQ

Does it support anchors and aliases?

Yes. Anchors (&) and aliases (*) are resolved, so the JSON contains the expanded values.

Can I convert JSON back to YAML?

Yes, with the JSON to YAML converter, linked below.