Skip to content

JSON to YAML

Convert JSON to YAML — and YAML back to JSON.

Live
Input

What this tool does

Convert JSON to YAML — and YAML back to JSON — without leaving your browser. The conversion is fully round-trippable: object key order, scalar types, and nesting depth are preserved. Paste a Kubernetes manifest, a GitHub Actions workflow, or a Docker Compose file and get strict JSON for programmatic editing; paste a JSON payload and read the YAML version in a pull-request diff that a human can actually skim.

Output uses block style by default (the readable form), with a configurable indent of 2 or 4 spaces. Strings that need escaping are quoted with single quotes when they contain no specials, and double quotes when they don’t — the same heuristic the yaml Python package uses, so the output round-trips through PyYAML cleanly.

How to use it

Paste JSON (or load the example), pick an indent (2 or 4 spaces), and read the YAML on the right. Toggle YAML → JSON instead to reverse direction — useful when iterating on a YAML config and you want to validate that it round-trips through a strict JSON parser.

Input: {"service":"devsmiths","version":2,"endpoints":[{"path":"/json/formatter","method":"GET"},{"path":"/json/repair","method":"POST"}],"public":true}

Output (YAML):

service: devsmiths
version: 2
endpoints:
  - path: /json/formatter
    method: GET
  - path: /json/repair
    method: POST
public: true

Limits and edge cases

  • YAML supports concepts that JSON doesn’t: anchors (&name), aliases (*name), and explicit tags (!Ref, !!binary). Going YAML → JSON expands anchors and drops tag annotations; the data survives, the YAML-specific syntax does not.
  • Multi-document YAML streams (separated by ---) are not supported in a single conversion — split them in your editor and convert each document individually.
  • The parser is YAML 1.2-compliant, which means it does not treat yes / no / on / off as booleans (the YAML 1.1 “Norway problem”). Quote these as strings if you mean text; spell them as true / false if you mean booleans.
  • Integer literals beginning with 0 are decimal, not octal — another YAML 1.2 vs 1.1 break that occasionally surprises teams migrating from PyYAML 5.x. Octal needs the explicit 0o prefix.
  • Numbers beyond ±2^53 lose precision in any JavaScript-based parser — both directions. Wrap large integers as strings if precision matters.
  • For invalid JSON input, run the JSON Repair tool first; the converter only accepts strict RFC 8259 JSON. Background reading: JSON vs YAML vs XML.

Frequently asked questions

Are YAML anchors and aliases preserved?
Going JSON → YAML: no. JSON has no concept of references, so the converter has nothing to anchor. Going YAML → JSON: anchors are resolved inline at parse time, so the resulting JSON contains the expanded value at every reference site. The data is preserved, the YAML sharing syntax is not.
What happens to YAML tags like !Ref, !Sub, or !!binary?
Custom tags (the !Ref / !Sub style common in CloudFormation) are not standard YAML 1.2 — they're application-specific extensions. The parser ignores the tag annotation and reads the scalar value beneath it, so `!Ref MyBucket` becomes the string `MyBucket`. For CloudFormation specifically, use the AWS CLI's native YAML loader; converting to JSON here will strip the !Ref semantics.
Why does my Kubernetes manifest with multiple `---` documents fail?
Multi-document YAML streams aren't supported in a single round-trip. The fix: split your manifest on `---` lines in your editor, convert each document individually, and merge the JSON outputs into an array on the consumer side. K8s itself accepts both YAML and JSON for apply, so for ad-hoc inspection just point `kubectl` at the YAML directly.
Why does `yes` come back as a string instead of a boolean?
Intentional. YAML 1.2 (which this parser implements) only treats `true` / `false` as booleans. YAML 1.1 treated `yes` / `no` / `on` / `off` as booleans, which caused the famous 'Norway problem' (the country code `NO` becoming `false`). The fix in YAML 1.2 was to restrict boolean spellings; the parser follows the spec.
Does the YAML output round-trip through PyYAML, ruamel.yaml, or Go's yaml.v3?
Yes for value-preserving round-trips — every scalar, list, and map survives. Comments are not preserved (JSON has no comments to preserve in the JSON → YAML direction), and anchor reuse is not reconstructed (the JSON intermediate has no anchors). For format-preserving round-trips through ruamel.yaml's RoundTripLoader, work in YAML directly; don't pass through JSON.
Can I convert JSON Schema to OpenAPI YAML?
Mechanically yes — paste the JSON Schema, get YAML out. Semantically it's only useful if the schema is already shaped like an OpenAPI document (with `paths`, `components`, etc.). For converting between JSON Schema draft versions or OpenAPI 3.0 vs 3.1, you need a schema-aware tool, not a syntactic converter.

Content reviewed by