How to convert YAML to JSON (and back)
This converter turns YAML into JSON and JSON into YAML in your browser. It is handy when a tool wants one format and your source is in the other: feeding a Kubernetes manifest to a JSON-only API, turning an API response into a readable config file, or checking how a tricky YAML document is actually interpreted.
Parsing uses the widely used js-yaml library. Nothing is uploaded, so it's safe to convert manifests that contain internal hostnames or (redacted) secrets.
How to use it
- Choose the direction: YAML → JSON or JSON → YAML.
- Paste your input and click Convert. If the input has a syntax error, the parser's message — including the line and column — is shown instead.
- Copy the result. Both JSON and YAML output use two-space indentation.
For example, this YAML:
service:
name: api
replicas: 3
ports:
- 80
- 443
public: trueconverts to:
{
"service": {
"name": "api",
"replicas": 3,
"ports": [
80,
443
],
"public": true
}
}YAML vs JSON
JSON is a strict, minimal data format that every language can parse, which makes it ideal for APIs. YAML is designed for humans: it uses indentation instead of braces, supports comments, and allows multi-line strings — which is why Kubernetes, Docker Compose, GitHub Actions, Ansible and OpenAPI specs favour it. Every JSON document is also valid YAML 1.2, but not the other way round.
| Feature | YAML | JSON |
|---|---|---|
| Comments | # like this | Not supported |
| Structure | Indentation | Braces and brackets |
| Strings | Quotes usually optional | Always double-quoted |
| Multi-line text | | (keep newlines) and > (fold) | \n escapes |
| Anchors / reuse | &anchor and *alias | Not supported |
Converting YAML to JSON drops comments, and resolves anchors and aliases into repeated values. Converting back won't restore them.
YAML gotchas the converter reveals
- Tabs aren't allowed for indentation. YAML requires spaces. A tab produces an error such as "bad indentation of a mapping entry".
- Unquoted values change type.
version: 1.10becomes the number1.1, andzip: 01234may lose its leading zero. Quote values that must stay strings. - The "Norway problem". Under YAML 1.1 rules (still used by many tools), unquoted
no,yes,onandoffbecome booleans, so the country codeNOcan turn intofalse.js-yamlfollows YAML 1.2, where onlytrueandfalseare booleans — but quote such values anyway if other tools will read the file. - Colons in values.
command: echo a: bis ambiguous; quote it:command: "echo a: b". - Inconsistent indentation. A list item indented one space less than its siblings silently becomes part of a different parent. Converting to JSON makes the real structure obvious.
Frequently asked questions
Is JSON valid YAML?
Yes, under YAML 1.2 any JSON document is valid YAML. The reverse isn't true: YAML features like comments, anchors and unquoted strings have no JSON equivalent.
Why did my comments disappear?
JSON has no comment syntax, so comments are dropped when YAML is parsed. Keep the original YAML file as the source of truth if comments matter.
Does it support multiple YAML documents separated by ---?
It converts a single document. For a multi-document file, convert each section between --- lines separately.
Can I validate a Kubernetes manifest with this?
It checks that the YAML is syntactically valid and shows its structure as JSON, but it doesn't validate against the Kubernetes schema. Use kubectl apply --dry-run=server or a schema validator for that.