JSON to YAML Converter

Our JSON to YAML converter transforms any valid JSON document into a clean, human-readable YAML representation in real time. Paste a config object, an API response, or a Kubernetes manifest and instantly see the YAML equivalent — with proper 2-space indentation, automatic quoting for ambiguous strings (yes/no/null/numbers-as-strings), nested array/object rendering, and one-click copy. Validation is built in: invalid JSON shows the exact error position so you can fix and re-convert. Everything runs in your browser, so sensitive payloads (API keys, secrets, JWTs) never leave your device. Use it for DevOps workflows, OpenAPI/Swagger specs, GitHub Actions, Ansible roles, Helm values, or anywhere YAML is preferred over JSON.

star 4.9
auto_awesome AI
New

JSON to YAML calculator

info Paste JSON to convert to YAML
0 lines 0 B 0 keys depth 0

lightbulb Tips

  • YAML uses 2-space indent — tabs are forbidden
  • Quote strings like "yes", "no", "null" to keep them as text
  • Quote ZIP codes ("01234") so leading zeros survive
  • YAML supports # comments — JSON does not
  • Round-trip JSON → YAML → JSON is lossless

How to Convert JSON to YAML in 3 Steps: Paste, Format, Copy

content_paste

Paste JSON

Paste any valid JSON — object, array, API response, or full Kubernetes manifest. The converter validates as you type.

swap_horiz

Convert

YAML appears instantly with 2-space indentation, type-safe quoting, and proper sequence/map nesting. Pick 4-space indent if your project requires it.

content_copy

Copy or Download

Click Copy for clipboard, or Download to save as a `.yaml` file ready to drop into your repo, kubectl apply, or docker compose up.

fact_check

Validate

Invalid JSON shows the parser error with line and column. Fix the issue and the YAML output refreshes automatically.

The Formula

JSON-to-YAML conversion parses the JSON text into an in-memory structure (objects → maps, arrays → sequences, primitives preserved as-is), then walks that tree emitting YAML syntax level-by-level. Indentation reflects nesting depth. Strings get quoted only when needed — when they contain special characters (`:` `#` `-` `&` `*` `!` `|` `>` `'` `"` `%` `@`), look like another type (`yes`, `no`, `null`, `~`, `on`, `off`, numeric-only), or are empty. Arrays use `- ` prefix; nested arrays/objects increase indent. The result is round-trippable: parsing it back with a YAML parser yields the same data structure as the original JSON.

JSON.parse(input) → emit YAML(parsed, indent, quoting)

lightbulb Variables Explained

  • input Raw JSON string (object, array, or scalar)
  • JSON.parse() Parses and validates JSON per RFC 8259 / ECMA-404
  • emit YAML() Walks the parsed tree and emits indented YAML 1.2.2
  • indent Number of spaces per level (2 is standard; 4 is occasionally used)
  • quoting Strings that resemble booleans, null, or numbers are quoted to prevent YAML type coercion

tips_and_updates Pro Tips

1

Use 2-space indentation in YAML — tabs are not allowed and cause silent parse failures

2

Quote strings that look like booleans (yes/no/on/off/true/false) or null to prevent unwanted type coercion

3

Empty values become null in YAML — write `null` or `~` explicitly for clarity in configs reviewed by humans

4

Multi-line strings: use `|` for literal blocks (preserves newlines), `>` for folded paragraphs (joins with spaces)

5

Comments start with `#` — JSON has no native comment support, so converting back to JSON drops them

6

For Kubernetes manifests, YAML is the convention — easier to review in PRs and document inline

7

Round-trip safety: JSON → YAML → JSON should preserve data; test with non-trivial inputs before relying on it

8

Anchors (&) and aliases (*) let you reuse YAML blocks, but don't survive a round-trip through JSON

9

Numeric strings like ZIP codes ("01234") need quoting in YAML — otherwise they become integers and lose leading zeros

10

Validate YAML with `yamllint`, `kubectl --dry-run=client`, or `docker compose config` before deploying

Convert any valid JSON document to clean YAML 1.2.2 instantly — paste, convert, copy. The converter handles deep nesting, preserves types, auto-quotes ambiguous strings (yes/no/null/numeric IDs), and emits 2-space indentation per the Kubernetes, Docker Compose, and Ansible conventions. Everything runs in your browser, so API keys, secrets, and JWT payloads never leave your device. Below: how the conversion works under the hood, JSON vs YAML differences that matter for DevOps, conversion patterns for Kubernetes manifests / Docker Compose / Helm values / OpenAPI specs, common YAML gotchas, and a cheat sheet for round-tripping safely.

JSON to YAML Converter Online: Convert Any JSON to YAML Instantly

Paste valid JSON — an object, array, scalar, API response, or full Kubernetes manifest — and the converter emits the YAML equivalent in real time. The conversion runs entirely in your browser using the native JSON.parse for input validation (per ECMA-404 / RFC 8259), then walks the parsed tree emitting YAML 1.2.2 syntax. 2-space indentation is the default — the de-facto standard across Kubernetes, Ansible, GitHub Actions, and Docker Compose. Switch to 4-space indent if your codebase requires it. Output is ready to paste into a `.yaml` file or pipe to `kubectl apply -f -`. The right-hand pane shows live byte and line counts so you can sanity-check size before committing.

How to Convert JSON to YAML: A 3-Step Workflow for Developers

Step 1: Paste your JSON into the editor. The converter validates as you type — invalid JSON shows the exact parser error with line and column. Step 2: The YAML output appears live in the right pane. No button click needed; every keystroke re-renders. Step 3: Click Copy (clipboard) or Download (`.yaml` file). For programmatic workflows, the same logic is exposed via the `/api/calculate` endpoint — POST JSON to it and receive the YAML in the response body. Round-trip safety: convert YAML back to JSON with the sister YAML to JSON Converter; the data model is preserved exactly (comments and anchors are YAML-only and don't survive the round trip).

JSON vs YAML: Key Differences in Syntax, Performance, and Use Cases

JSON and YAML represent the same data model — maps (objects), sequences (arrays), and scalars (string/number/bool/null) — but with very different surface syntax. JSON is brace-and-quote heavy: every key gets `"`, every map gets `{}`, every array gets `[]`, and every separator is explicit (`:` and `,`). YAML is indentation-driven: nesting is implied by 2-space indent, sequences use `- ` prefix, and most strings don't need quotes. JSON parses 5–10× faster across all major language runtimes, has zero ambiguity, and is the right choice for APIs, message queues, log streams, and storage formats. YAML supports comments (`#`), anchors and aliases for re-use (`&name` / `*name`), multi-document streams (`---`), and explicit type tags (`!!str`, `!!int`) — strengths that make it the right choice for source-controlled configs, CI/CD pipelines, infrastructure-as-code, and Kubernetes manifests. Pick JSON for machines, YAML for humans, and convert between them at the boundary.

Convert Nested JSON Objects to YAML: Arrays, Maps, and Deep Trees

Deep nesting is where JSON-to-YAML conversion earns its keep — tracking braces and indentation by hand at 5+ levels is error-prone. The converter walks the parsed JSON tree recursively. For each map (object), keys are emitted in source order with `key: value` syntax; nested values are indented by 2 more spaces. For each sequence (array), items use `- ` prefix; nested objects under a `-` start on the same line as the dash and inherit the next indent level. Mixed structures — arrays of objects, objects containing arrays of objects, recursively — all render correctly. Maximum depth is bounded only by your browser's call stack (~10,000+ frames in modern browsers, far beyond any realistic config). Test with your own fixtures: parse the YAML output back to JSON and assert structural equality with the input.

JSON to Kubernetes YAML: ConfigMaps, Manifests, and Helm Values

Kubernetes manifests are the most common use case for this converter. Many tools (kubectl, Lens, k9s, Helm) emit JSON via `-o json` flags; the canonical source-of-truth format committed to Git is YAML. Paste the JSON output of `kubectl get deployment -o json` and the converter produces a clean manifest ready to commit. apiVersion, kind, metadata, and spec hierarchies preserve exact field ordering. For Helm chart values, paste your JSON values and drop the YAML into `values.yaml` — Helm templates pick it up unchanged. For Kustomize overlays, convert your patch object and add to the `patchesStrategicMerge` list. Validate the output with `kubectl apply --dry-run=client -f file.yaml` before committing — it catches schema-level issues that YAML syntax validation alone would miss.

JSON to Docker Compose YAML: Service Definitions and Multi-Container Configs

Docker Compose files are pure YAML conforming to the Compose Specification (compose-spec.io). When you have programmatic JSON output — from a config generator, a previous Compose v2 export, or a templating script — convert it here and paste into `docker-compose.yaml`. Top-level keys (`services`, `networks`, `volumes`, `configs`, `secrets`) and their nested specs (image, ports, environment, depends_on, healthcheck) all convert correctly. Watch for ports: shorthand strings like `"8080:80"` must stay quoted in YAML to prevent parsing as a sexagesimal number — the converter handles this automatically. Validate with `docker compose config` before `docker compose up`; it parses, merges multiple files, and prints the resolved config exactly as the engine will run it.

YAML Syntax Rules: Indentation, Anchors, Multiline Strings & Type Coercion

YAML's indentation rules are strict: 2 spaces per level (4 also valid but rare), tabs are forbidden, and sibling keys must align exactly. Sequences (`- item`) and maps (`key: value`) can nest freely. Multi-line strings come in two flavors: literal blocks (`|`) preserve every newline; folded blocks (`>`) join lines with spaces (paragraph-style). Anchors (`&name`) and aliases (`*name`) let you define a YAML node once and reuse it elsewhere — common in Compose files for shared service templates. Explicit type tags (`!!str`, `!!int`, `!!bool`, `!!null`) override YAML's auto-typing when you need a string that looks like a number, or vice versa. The converter quotes ambiguous strings automatically: `"yes"`, `"no"`, `"null"`, `"~"`, numeric-looking values like `"01234"`, and any string containing YAML special characters (`:`, `#`, `-`, `&`, `*`, `!`, `|`, `>`, `'`, `"`, `%`, `@`).

Validate YAML Syntax: Common Errors, Tab vs Space, and Type Pitfalls

Six errors account for 95% of broken YAML in the wild. (1) Tabs anywhere — even one tab character breaks parsing. Configure your editor to insert spaces. (2) Inconsistent indentation — a sibling key off by one column is a parse error. (3) Missing space after `:` — `key:value` is invalid; `key: value` is correct. (4) Unquoted strings that look like booleans (`yes`, `no`, `on`, `off`) — get coerced to true/false in YAML 1.1 (older parsers). YAML 1.2 narrowed booleans to `true`/`false` only, but defensive quoting is still wise. (5) Numeric strings without quotes — `01234` becomes integer 1234, losing the leading zero. (6) Missing space after `-` — `-item` is a string starting with a dash; `- item` is a sequence entry. Validate with `yamllint`, the YAML extension in VS Code, or domain-specific validators (`kubectl --dry-run`, `docker compose config`, `ansible-playbook --syntax-check`).

JSON to YAML Converter for APIs: Response Bodies, OpenAPI, and Swagger

API workflows benefit from JSON-to-YAML in two places. First, OpenAPI 3.x specs are commonly authored in YAML (more readable for path/parameter trees) but exported as JSON for tooling — convert in either direction as your editing flow requires. The converter preserves required fields, schema definitions, $ref pointers, and example bodies. Second, when documenting an API, paste a sample JSON response and present the YAML version in your docs — easier for readers to scan deeply nested response bodies. For Swagger UI integration, both `swagger.yaml` and `swagger.json` are accepted; many teams keep YAML in source control and emit JSON at build time. Round-trip safety holds for OpenAPI specs since they don't use comments or anchors in canonical form.

JSON to YAML for DevOps: Ansible Playbooks, GitHub Actions, and CI/CD

Almost every modern CI/CD platform uses YAML for pipeline definitions: GitHub Actions (`.github/workflows/*.yaml`), GitLab CI (`.gitlab-ci.yml`), CircleCI (`.circleci/config.yml`), Travis (`.travis.yml`), Drone, Concourse, Argo Workflows, Tekton. When you have a JSON config — from a generator, a previous version control export, or a programmatic builder — paste here and emit YAML. Ansible playbooks specifically lean heavily on YAML's list-of-tasks structure with anchors for reused blocks; the converter outputs sequences cleanly so you can paste under `tasks:` without further edits. For GitHub Actions, the trickiest part is `if:` conditions and matrix strategies — keep the converted YAML, then add comments explaining intent (a YAML-only feature you'll lose if you go back to JSON).

JSON to YAML Conversion Edge Cases: Comments, Booleans, and Null Values

Five edge cases break naive converters. (1) Comments: JSON has none, YAML supports `#`. Round-tripping JSON → YAML → JSON is lossless, but YAML → JSON → YAML drops every comment. Keep YAML as your source of truth when comments matter. (2) Boolean coercion: legacy YAML 1.1 parsers treat `yes`/`no`/`on`/`off` as booleans. Modern parsers (1.2.2) only treat `true`/`false` that way, but defensive quoting prevents surprises. (3) Null: JSON `null` maps to YAML `null`, `~`, or empty value. The converter emits `null` for clarity; some tools prefer empty (`key:`) but it can be ambiguous with empty strings. (4) Numeric strings: `"01234"` (a US ZIP code) loses the leading zero if unquoted in YAML — the converter quotes it. (5) Floats with trailing zeros: `1.50` round-trips as `1.5` because both JSON and YAML use canonical numeric representation. If trailing zeros matter (currency, version strings), serialize as strings.

JSON to YAML Cheat Sheet: Type Mapping, Style Choices & Round-Trip Tips

Type mapping at a glance: JSON object → YAML map (block style); JSON array → YAML sequence (`-` items); JSON string → YAML string (auto-quoted when ambiguous); JSON number → YAML scalar with same numeric value; JSON true/false → YAML true/false; JSON null → YAML null. Style choices: prefer block style (multi-line, indented) for readability over flow style (`{key: value, ...}` JSON-like compact); use 2-space indent always; emit keys in source order (matches JSON's behavior). Round-trip tips: (1) JSON → YAML → JSON is lossless. (2) YAML → JSON drops comments, anchors (expanded), explicit tags, multi-document streams. (3) Always quote strings that look like booleans, null, or numbers. (4) Test your output with the actual tool that consumes it (kubectl, docker compose, ansible-playbook) — these have stricter validation than generic YAML parsers. (5) Keep both versions in source control if your team uses both formats; treat one as canonical (typically YAML for configs, JSON for APIs) and regenerate the other on build.

code

Embed this JSON to YAML Converter on your site

Free for any site. Copy the snippet below and paste into your HTML — no attribution required beyond the built-in credit link.

<iframe src="https://calculators.im/embed/json-to-yaml-converter" width="100%" height="720" style="border:0;max-width:100%;" loading="lazy" title="JSON to YAML Converter by Calculators.im"></iframe>
<p style="font-size:12px;text-align:center;color:#64748b;margin-top:6px;">Powered by <a href="https://calculators.im/json-to-yaml-converter?utm_source=embed&utm_medium=snippet&utm_campaign=json-to-yaml-converter">JSON to YAML Converter</a> by Calculators.im</p>
open_in_new Preview embed Auto-resizing iframe. Mobile responsive. Works with WordPress, Ghost, Webflow, and plain HTML.

Frequently Asked Questions

sell

Tags