YAML to JSON Converter

Our YAML to JSON converter parses any valid YAML 1.2 document and emits the JSON equivalent in real time. Paste a Kubernetes manifest, a Docker Compose file, an Ansible playbook, or an OpenAPI spec and instantly see the JSON form — preserving types correctly (numbers stay numbers, true/false stay booleans, null stays null) and stripping comments cleanly. Validation flags indentation errors, type-coercion ambiguity, and unsupported syntax (anchors, multi-document streams) with clear messages. Everything runs in your browser, so secrets and config never leave your device. Use it for API request bodies, programmatic config processing, or any tool that consumes JSON instead of YAML.

star 4.9
auto_awesome AI
New

YAML to JSON calculator

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

lightbulb Tips

  • YAML 1.2: only `true`/`false` are booleans (no yes/no)
  • Comments (#) are stripped — JSON has no comment syntax
  • Anchors (&name) and aliases (*name) get expanded inline
  • Multi-document streams (---) need to be split first
  • Tabs in indentation cause parse errors — use spaces only

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

content_paste

Paste YAML

Paste any YAML 1.2 document — Kubernetes manifest, Compose file, Ansible playbook, OpenAPI spec, or custom config. The parser validates as you type.

swap_horiz

Convert

JSON appears instantly with type-correct values (numbers stay numbers, true/false stay booleans), comments stripped, and anchors expanded inline. Pick 2-space, 4-space, or minified output.

content_copy

Copy or Download

Click Copy for clipboard or Download to save as a `.json` file ready for API request bodies, kubectl apply via stdin, or programmatic config processing.

fact_check

Validate

Invalid YAML shows the parse error with line and column. Common fixes: replace tabs with spaces, fix indentation, quote ambiguous strings.

The Formula

YAML-to-JSON conversion parses the YAML text into an in-memory structure (block maps → objects, sequences → arrays, scalars → typed values), then re-emits it as JSON. Type inference follows YAML 1.2 core schema: bare `true`/`false` → boolean, `null`/`~` or empty → null, integer/float regex → number, everything else → string (quoted strings always stay strings). Comments (`#`) are stripped. Anchors (`&`/`*`) are expanded inline. Round-trip safety holds: parsing the JSON back to YAML gives the same data model (minus comments and anchor sharing).

parse YAML(input) → JSON.stringify(parsed, null, indent)

lightbulb Variables Explained

  • input Raw YAML 1.2 string (block-style maps, sequences, and scalars)
  • parse YAML() Tokenizes by indent, walks the tree, infers types per YAML 1.2 core schema
  • JSON.stringify() Emits canonical JSON per RFC 8259 with chosen indentation
  • indent Number of spaces per level in the JSON output (0 = minified)

tips_and_updates Pro Tips

1

YAML 1.2 booleans are ONLY true/false — `yes`, `no`, `on`, `off` are strings (unlike YAML 1.1 where they were booleans)

2

Empty values become null in JSON — write `null` or `~` explicitly to make the intent clear before conversion

3

Quoted strings in YAML stay strings in JSON, even if they look like numbers (`"01234"` stays a string)

4

Comments (`#`) are stripped — JSON has no comment support; keep comments in the YAML source if you need them

5

Anchors (`&name`) and aliases (`*name`) are expanded inline — the JSON output is fully resolved, with no shared references

6

Multi-document YAML streams (separated by `---`) need to be split before conversion — JSON is single-document

7

For API consumption, prefer minified JSON (no indentation) to reduce payload size by 20-60%

8

Round-trip YAML → JSON → YAML loses comments and anchor structure, but the data model is preserved

9

Validate the JSON output against a JSON Schema if your downstream consumer is strict about field types

10

For very large YAML files (10MB+), prefer command-line tools like `yq -o json input.yaml` over browser conversion

Convert any valid YAML 1.2 document to clean JSON instantly — paste, parse, copy. The converter handles deep nesting, infers types correctly per YAML 1.2 core schema (only `true`/`false` are booleans, no Norway bug), strips comments, expands anchors inline, and emits canonical JSON per RFC 8259. Everything runs in your browser, so Kubernetes secrets, API keys, and JWT payloads never leave your device. Below: how the conversion works under the hood, YAML vs JSON differences that matter for DevOps, conversion patterns for Kubernetes / Docker Compose / Ansible / OpenAPI, common YAML pitfalls (the Norway bug, tab errors, anchor expansion), and a cheat sheet for round-tripping safely.

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

Paste valid YAML — a Kubernetes manifest, Compose file, Ansible playbook, OpenAPI spec, or any YAML 1.2 document — and the converter emits the JSON equivalent in real time. The conversion runs entirely in your browser using a YAML 1.2 parser, then walks the parsed tree emitting JSON via JSON.stringify (per ECMA-404 / RFC 8259). Pick 2-space (default, human-readable), 4-space (some enterprise codebases), or minified (APIs, network payloads) output. Output is ready to paste into a `.json` file or pipe to `kubectl apply -f -` (which accepts JSON via stdin). The right-hand pane shows live byte and line counts so you can sanity-check size before committing.

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

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

YAML vs JSON: Key Differences in Syntax, Comments, and Type Handling

YAML and JSON represent the same data model — maps (objects), sequences (arrays), and scalars (string/number/bool/null) — but with very different surface syntax. YAML is indentation-driven: nesting is implied by 2-space indent, sequences use `- ` prefix, and most strings don't need quotes. JSON is brace-and-quote heavy: every key gets `"`, every map gets `{}`, every array gets `[]`, and every separator is explicit (`:` and `,`). 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. JSON parses 5–10× faster, has zero ambiguity, and is the right choice for APIs and storage. Convert at the boundary: YAML for humans, JSON for machines.

Convert Nested YAML to JSON: Maps, Sequences, and Deep Trees

Deep nesting is where YAML-to-JSON conversion shines — tracking indentation by hand at 5+ levels is error-prone. The converter walks the parsed YAML tree recursively. For each block map, keys are emitted in source order with `"key": value` JSON syntax; nested values get `{...}` braces. For each block sequence, items emit as `[...]` JSON arrays; nested objects under a `-` become `{...}` array elements. Mixed structures — sequences of maps, maps containing sequences of maps, recursively — all convert 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 JSON output back to YAML and assert structural equality with the input.

YAML Type Inference: Booleans, Numbers, Null, and the Norway Problem

YAML's loose type inference is the source of many bugs in real-world configs. YAML 1.2 (the modern standard, target of this converter) narrowed the rules to be safer. Booleans: ONLY `true` and `false` (case-insensitive). YAML 1.1 also treated `yes`/`no`/`on`/`off` as booleans, which famously broke configs containing Norway's country code `NO` (silently converted to `false`) — the 'Norway problem'. Most modern parsers (js-yaml, PyYAML 6+, Snakeyaml) default to 1.2 behavior. Null: `null`, `~`, or empty value all become JSON null. Numbers: digit patterns matching JSON's integer/float syntax become JSON numbers; everything else stays a string. Strings: quoted values always stay strings; numeric strings like ZIP codes (`"01234"`) need quoting in YAML to survive conversion. The converter respects these rules strictly.

Convert Kubernetes YAML Manifests to JSON for the K8s API

Kubernetes accepts both YAML and JSON via its API server, kubectl, and client libraries. Most teams keep YAML in source control (PRs are easier to review) but feed JSON to programmatic tooling — custom controllers, GitOps pipelines, Helm post-renderers, or webhooks. Paste your manifest (Pod, Deployment, Service, ConfigMap, etc.) and copy the JSON output. The converter preserves apiVersion, kind, metadata, and spec hierarchies in field-order. Validate with `kubectl apply --dry-run=client -f -` (which accepts JSON on stdin) before committing. For multi-resource manifests separated by `---`, split into individual documents first — JSON has no multi-document syntax.

Convert Docker Compose, Ansible, and CI/CD YAML to JSON

Three high-volume use cases beyond Kubernetes. Docker Compose: paste a `docker-compose.yaml` and copy JSON for tools like Kompose (migrates Compose to K8s), custom orchestrators, or programmatic config transformations. Ansible: convert playbooks to JSON for documentation tooling, custom CI integrations, or REST/GraphQL APIs that store playbook definitions. CI/CD pipelines: GitHub Actions (`.github/workflows/*.yml`), GitLab CI (`.gitlab-ci.yml`), CircleCI, Travis — convert any of these to JSON for analytics, programmatic edits, or audit-log archival. Note: Jinja2 expressions (`{{ var }}`), Helm template syntax (`{{ .Values.x }}`), and similar templating remain as plain strings in JSON — they're not evaluated by the converter.

Convert OpenAPI / Swagger YAML to JSON for API Tooling

OpenAPI 3.x specs are commonly authored in YAML (more readable for path/parameter trees) but consumed as JSON by older tooling — legacy Swagger UI builds, certain enterprise API gateways, and some code generators. Paste your `openapi.yaml` (or `swagger.yaml`) and download `openapi.json`. The converter preserves `$ref` pointers exactly (no resolution), schema definitions, response examples, and security schemes. After conversion, validate with the official OpenAPI validator (Spectral CLI, openapi-cli, swagger-cli) to confirm schema compliance. Many teams keep YAML in source control and emit JSON at build time — both `swagger.yaml` and `swagger.json` are fully equivalent for API consumers.

YAML Parse Errors: Tabs, Indentation, and Common Fixes

Six errors account for 95% of YAML parse failures. (1) Tabs anywhere in indentation — YAML forbids tabs entirely, even one tab character breaks parsing. (2) Inconsistent indentation — sibling keys must align at the exact same column. (3) Missing space after `:` in maps — `key:value` is invalid; `key: value` is correct. (4) Missing space after `-` in sequences — `-item` is a string starting with dash; `- item` is a sequence entry. (5) Unquoted special characters at the start of a value — `@`, `` ` ``, `%`, `*`, `&` need quoting. (6) Unsupported features in the converter: anchors (`&name`), aliases (`*name`), and multi-document streams (`---`) — for these, use a full YAML library like js-yaml, PyYAML, or `yq`. The error message shows line and column where parsing failed.

YAML Anchors, Aliases, and Multi-Document Streams in JSON Conversion

Three YAML features have no direct JSON equivalent and need special handling. (1) Anchors (`&name`) and aliases (`*name`) let YAML reference a node and reuse it elsewhere — common in Compose files for shared service templates and CloudFormation for shared parameters. JSON has no reference syntax, so the converter expands aliases inline (each alias becomes a full copy). The data is preserved but the JSON is larger and shared-reference structure is lost. (2) Multi-document streams (`---` separator) represent multiple top-level values in one file — common for bundling Kubernetes resources. JSON has only single root values per document. Split the YAML into separate files first or wrap docs in a JSON array `[doc1, doc2, doc3]`. (3) Comments (`#`) are YAML-only — they're stripped entirely during conversion. Keep YAML as source of truth if comments matter.

Round-Trip Safety: YAML → JSON → YAML and Edge Cases

Five round-trip considerations every developer should know. (1) Data model: YAML → JSON → YAML preserves keys, values, types, and nesting exactly. The data is identical going in and coming back out. (2) Comments: lost forever — JSON has no comment syntax. Keep YAML as source of truth if you have inline docs. (3) Anchors/aliases: expanded on the way to JSON, never recreated on the way back. The output YAML has duplicated content where the source had shared references. (4) Key order: YAML preserves source order; the converter preserves it through to JSON; round-trip back to YAML keeps the same order. (5) Type tags (`!!str`, `!!int`) — only emitted when needed for disambiguation. A string `"01234"` survives round-trip because the JSON keeps it quoted; an unquoted YAML `01234` parses as an integer and round-trips as the number 1234, losing the leading zero. Quote ambiguous values defensively.

YAML to JSON Cheat Sheet: Type Mapping, Tools, and Best Practices

Type mapping at a glance: YAML map → JSON object; YAML sequence → JSON array; YAML scalar (per type inference) → JSON string/number/boolean/null; YAML !!str tag → JSON string (forced); YAML null/~/empty → JSON null; YAML true/false → JSON boolean; YAML integer pattern → JSON integer; YAML float pattern → JSON number. Tool comparison: this converter (browser, instant, no install, 95% of real YAML) vs `yq -o json` (CLI, large files, JSONPath queries) vs `js-yaml`/`PyYAML` (full library, anchors and multi-doc supported, programmatic use). Best practices: (1) Always quote ambiguous values (yes/no/on/off/null/numeric IDs) in YAML source. (2) Use 2-space indent (the de-facto standard). (3) Validate the JSON output against your downstream consumer's schema (JSON Schema, OpenAPI, K8s OpenAPI) — type errors surface here. (4) Keep YAML as canonical source and regenerate JSON at build time when possible.

code

Embed this YAML to JSON 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/yaml-to-json-converter" width="100%" height="720" style="border:0;max-width:100%;" loading="lazy" title="YAML to JSON 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/yaml-to-json-converter?utm_source=embed&utm_medium=snippet&utm_campaign=yaml-to-json-converter">YAML to JSON 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