02 / YAML / yaml-json

YAML ↔ JSON Converter

Convert YAML to JSON and JSON to YAML.

ReadyLocal processing
02 · Workspace

How to use

  1. 01Paste YAML into the YAML input box. The Direction control starts on YAML → JSON.
  2. 02The JSON output updates live as you type. If the YAML can't be parsed, an Invalid YAML message shows the line and column.
  3. 03Choose 2 spaces or 4 spaces under Indent for the JSON output.
  4. 04Use Copy output, or Download to save the result as converted.json.
  5. 05Press Swap ⇄ to move the JSON into the input and switch to JSON → YAML for a round trip.

What is this tool?

This converter parses YAML and writes the equivalent pretty-printed JSON, which you need when an API, a JavaScript test or a JSON-only tool consumes data that people maintain in YAML. Anchors and aliases are resolved into full values, and YAML syntax errors are reported with a line and column instead of producing broken output. Conversion happens in your browser, so configs never leave your machine.

How YAML types map to JSON

Mappings become JSON objects, sequences become arrays, and plain scalars are typed by their content. For example, replicas: 3 becomes the number 3, DEBUG: false becomes the boolean false, and a bare ~ or null becomes null. Everything else becomes a string. Because the parser follows YAML 1.2, yes, no, on and off are strings, not booleans. Dates such as 2024-01-01 also stay strings, since JSON has no date type.

Some conversions surprise people. version: 1.10 becomes the number 1.1, and a file mode like 0755 becomes the number 755. If a value must stay text, quote it in the YAML (version: "1.10") before converting.

What gets lost converting YAML to JSON

JSON has no comments, so every # comment is dropped. Anchors and aliases are expanded. If a defaults block is defined once with &defaults and referenced several times with *defaults, the JSON contains a full copy at each reference, which can make the output much larger than the source. Merge keys (<<: *defaults) are not applied. They come through as a literal "<<" key, so flatten those by hand if the consumer expects merged fields.

The converter handles one document at a time. A file with several documents separated by --- is reported as an error, so split it first and convert each document separately. Duplicate keys in a mapping are also rejected rather than silently overwritten, so the JSON never hides a value that one of the duplicates would have lost.

Common use cases

  • Turning a YAML fixture into a JSON request body for an API test
  • Feeding a Kubernetes or Compose config into jq or a JSON-only linter
  • Converting an OpenAPI spec written in YAML into JSON for a code generator
  • Checking how a YAML value is actually typed, for example whether a value parsed as a number or a string
  • Loading YAML-maintained test data into a JavaScript or Postman test that expects JSON

FAQ

How do I convert YAML to JSON?

Paste the YAML with the direction set to YAML → JSON. The JSON appears immediately, and you can copy it or download it as converted.json.

Why did my YAML value turn into a number or boolean?

Unquoted scalars are typed by their content, so 3 becomes a number and true becomes a boolean. Quote the value in the YAML to keep it as a string.

What happens to comments and anchors?

Comments are dropped, because JSON can't represent them. Anchors and aliases are expanded into full copies of the referenced values.

Can I convert a YAML file with multiple documents?

No. The input must be a single YAML document. Split files on their --- separators and convert each one separately.

Is my YAML uploaded during conversion?

No. Parsing and conversion run locally in your browser.