Convert YAML to JSON Without Losing Track of Data Types

Start with the task you actually need to finish

  • Converting a Kubernetes or Helm values.yaml to JSON for kubectl or an API call.
  • Turning a docker-compose.yml into JSON to read it in a script.
  • Changing an OpenAPI or Swagger spec between YAML and JSON.

A practical check before you begin

JSON cannot keep ordinary YAML comments. Save the documented original and quote values that must remain text, such as zero-padded IDs or version labels. Review arrays, numbers, and null values after conversion, not just indentation.

Follow the workflow and review the result

  1. Choose YAML → JSON or JSON → YAML at the top.
  2. Paste your YAML or JSON into the left box.
  3. Read the converted result on the right. It updates as you type.
  4. If an error box appears, fix the line it points to.
  5. Copy the result or download it as a .json or .yaml file.

YAML vs JSON: what is the difference?

Both store the same kinds of data: objects (maps), lists, strings, numbers, true/false and null. JSON uses braces, brackets and quotes. YAML uses indentation and dashes, supports comments and is shorter to write. Every JSON file is also valid YAML 1.2, but not every YAML file maps cleanly to JSON — comments, anchors and custom tags have no JSON equivalent.

What changes during conversion

Keys, values, nesting and list order stay the same. Comments are removed because JSON cannot hold them. Anchors and aliases (& and *) are expanded into full copies. Dates written without quotes become ISO date strings. If you need a value to stay text, such as a version like 1.10, wrap it in quotes in the YAML.

Common YAML errors and fixes

Tabs: YAML only allows spaces for indentation — replace tabs with spaces. Uneven indent: keep children at the same number of spaces. Missing space after a colon: write key: value, not key:value. Special characters: quote strings that start with *, &, @, ! or contain ': '.

Limits worth knowing before you rely on the output

Round-tripping does not preserve every comment, tag, alias, or formatting choice.