My Tool Studio
Developer

YAML to JSON Converter

This YAML to JSON converter parses YAML as you type and returns pretty-printed JSON. It uses js-yaml, a YAML 1.2 parser, so mistakes such as bad indentation, tabs or duplicate keys are highlighted on their line with a plain-English reason instead of being guessed at. Files with several documents separated by --- become a JSON array, JSON Lines or just the first document, as you choose. Anchors, aliases and << merge keys are expanded. Pick a schema, such as Failsafe to keep every value as text, and 2 or 4 spaces, tabs or minified output. Paste, drop, upload or load YAML from a URL, then copy or download the result.

Always freeNo sign upRuns in your browser
Swap: JSON to YAML
JSON appears here.

How to use

01

Add your YAML

Paste YAML into the left pane, drop or upload a .yaml or .yml file, use Load URL, or press Try sample to load a two-document file with an anchor, an alias and a << merge key.

02

Choose the output

Pick the Schema, how several documents are written, and the Indent. The JSON updates as you type; untick Convert as you type to convert only when you press the button.

03

Fix errors or copy

If the YAML is invalid, the line is highlighted and the error shows the column and nearby lines, with Go to line to jump there. Otherwise copy the JSON or download .json or .jsonl.

Why YAML to JSON Converter

Anchors, aliases and merge keys: YAML input vs JSON output

Anchors let a YAML file define a block once and reuse it. The sample on this page defines &defaults with an image and a replica count, then pulls it into web with <<: *defaults and adds a port. JSON cannot express that reuse, so the converter writes the final values out in full.

The sample also has a second document after ---, so the whole output is a JSON array with two objects.

YAMLJSON
defaults: &defaults with image: nginx:1.27 and replicas: 2"defaults": {"image": "nginx:1.27", "replicas": 2}
web: with <<: *defaults and port: 80"web": {"image": "nginx:1.27", "replicas": 2, "port": 80}
--- followed by a second documentThe output becomes an array: [ {first}, {second} ]
ports: with - port: 80 and targetPort: 8080"ports": [{"port": 80, "targetPort": 8080}]

Which schema to choose

The schema decides how unquoted values are typed. The same line, version: 1.10, can come out differently depending on the choice, so pick the one that matches the tool that will read your YAML.

SchemaNumbers and booleansDatesMerge keys (<<)
YAML 1.2 + merge keys and dates (default)TypedBecome ISO timestampsExpanded
YAML 1.2 coreTypedStay stringsNot expanded
JSON schema (strict)Only JSON-style values are typedStay stringsNot expanded
FailsafeEverything is a stringStay stringsNot expanded

Common questions

Does it support multiple YAML documents separated by ---?
Yes. By default each document becomes an item in a JSON array, in the same order. The Several documents menu can instead write JSON Lines, one document per line, or keep only the first document. A single document is never wrapped in an array.
How are YAML anchors and aliases converted to JSON?
JSON has no references, so each alias is replaced by a full copy of the anchored value. A << merge key copies the anchored keys into the mapping, and keys written directly in that mapping override the merged ones.
Can I convert a Kubernetes manifest or docker-compose.yml to JSON?
Yes. Paste the file and convert; multi-document manifests become a JSON array. The tool checks YAML syntax only, not whether the fields are valid for Kubernetes or Compose.
How do I convert YAML to JSON on the command line?
With yq version 4, run yq -o=json file.yaml. With Python and PyYAML installed, pipe the file into python -c 'import sys, yaml, json; print(json.dumps(yaml.safe_load(sys.stdin), indent=2))'.
Why does YAML to JSON turn my value into a number or a date?
Unquoted values are typed: 10 becomes a number, true becomes a boolean, and an unquoted date like 2024-01-15 is read as a timestamp and written as 2024-01-15T00:00:00.000Z. Pick the YAML 1.2 core schema to stop date conversion, or Failsafe to keep every value as a string. Quoting a value in the YAML also keeps it as text.
Why does the YAML to JSON converter reject tabs?
The YAML spec does not allow tabs for indentation, only spaces. The line with the tab is highlighted; replace the leading tabs with spaces, usually 2 per level.
What happens to YAML comments when converting to JSON?
They are dropped. JSON has no comment syntax, so only the data is kept.
Can I convert JSON back to YAML?
Yes, with the JSON to YAML Converter. It writes 2-space block YAML as you type and quotes strings that would otherwise change type.
Can the YAML to JSON converter accept duplicate keys?
By default a repeated key in the same mapping is an error, because it usually means a copy and paste mistake. Tick Allow duplicate keys and the last value wins instead, which matches how some other YAML tools behave.

More Developer tools

View all