YAML to JSON converter
Paste YAML, get JSON. Anchors are expanded, block scalars become escaped strings, and comments are dropped — because JSON has nowhere to put them.
Conversion happens in this browser tab. Nothing is uploaded, logged, or stored.
How the conversion works
This direction is the harder one. YAML has features JSON simply does not have, so the converter has to decide what to do with them rather than copy them across.
| YAML feature | What happens in JSON |
|---|---|
Comments (#) | Dropped. JSON has no comment syntax. |
Anchors and aliases (&x, *x) | Expanded — the referenced value is written out in full at every use. |
Multi-document files (---) | Only the first document is converted. The YAML validator will show you how many there are. |
Block scalars (|, >) | A single JSON string with escaped newlines; see block scalars. |
Non-string keys (1: value) | Coerced to strings. JSON keys are always strings. |
Explicit tags (!!timestamp) | Resolved to a plain value where possible. |
Comments being dropped is the loss that surprises people most. If your YAML is
documentation as much as configuration — and a well-written values.yaml
usually is — round-tripping through JSON strips that documentation permanently. Keep
the YAML as the source of truth and treat the JSON as a build artifact.
Anchors, expanded
Aliases are the clearest illustration of what "lossy" means here. The YAML on the left defines a block once and reuses it. The JSON on the right has no way to say "the same as above", so the block is repeated.
defaults: &defaults
retries: 3
timeout: 30
staging:
<<: *defaults
host: stg.example.com
production:
<<: *defaults
host: example.com{
"defaults": { "retries": 3, "timeout": 30 },
"staging": {
"retries": 3,
"timeout": 30,
"host": "stg.example.com"
},
"production": {
"retries": 3,
"timeout": 30,
"host": "example.com"
}
}The JSON is correct and equivalent. It is also three times longer and no longer carries the intent that staging and production share a base. Converting back will not restore the anchors.
Doing the same thing in code
Python
import json, yaml
with open("config.yaml") as f:
data = yaml.safe_load(f) # safe_load, never load()
print(json.dumps(data, indent=2))
Use safe_load. Plain yaml.load() can construct arbitrary
Python objects from a crafted document, which is a remote code execution path if the
YAML came from anywhere you do not control.
Node.js
import fs from "node:fs";
import yaml from "js-yaml";
const data = yaml.load(fs.readFileSync("config.yaml", "utf8"));
console.log(JSON.stringify(data, null, 2));
Multiple documents in one file
# Python — a list of documents
docs = list(yaml.safe_load_all(open("manifests.yaml")))
print(json.dumps(docs, indent=2))
# Command line
yq -o=json '.' manifests.yaml
Errors you are likely to hit
Tabs used for indentation
YAML forbids tabs as indentation, full stop. An editor configured to insert tabs
will produce a file that looks perfectly aligned and fails to parse. Set your editor
to two spaces for .yml and .yaml.
Missing space after the colon
key:value is a single scalar string, not a mapping. YAML needs
key: value. This one is easy to miss because most languages accept the
compact form.
The value looks like something else
An unquoted 1.10 becomes the float 1.1, losing the trailing zero.
An unquoted 3:00 can parse as a sexagesimal number under YAML 1.1. Version
strings, times, and anything with a leading zero want quotes.
A colon inside an unquoted value
message: Error: not found is ambiguous and most parsers reject it.
Quote the whole value: message: "Error: not found".
If you are staring at a parser error right now, the YAML error reference lists the common messages verbatim with the fix for each.
Nothing leaves this tab
The YAML people paste here is usually a values.yaml, a CI pipeline
definition, or an Ansible playbook — files that sit in private repositories and name
every host, queue, and service account an organisation runs. Even with the secrets
templated out, the structure alone maps your infrastructure.
None of it reaches us. Parsing and conversion happen locally, in JavaScript, on your machine. We could not produce your document if someone asked us to, because we never received it.