induwara.lk
induwara.lkDeveloper · Data formats

YAML to JSON Converter (bidirectional)

Convert YAML to JSON and JSON to YAML in one place. Auto-detects the direction, expands anchors and aliases, handles multi-document streams, pinpoints parse errors by line, and verifies every conversion with a round-trip check. Runs fully in your browser — nothing is uploaded.

By Induwara AshinsanaUpdated Jun 25, 2026
YAML ⇄ JSON Converter
Round-trip verified

Detected: YAML → JSON

Try a sample
paste YAML or JSON

Valid. Output re-parses to an identical structure (round-trip verified).

Documents
1
Keys
9
Nodes
12
Spec-driven (YAML 1.2.2 + RFC 8259) · 100% client-side · no upload

How it works

The converter is a deterministic parse-then-serialize pipeline. There are no heuristics and no network calls: the YAML 1.2.2 Core Schema fixes how every scalar resolves, and RFC 8259 fixes the JSON it emits, so the same input always produces the same output.

  1. Detect direction. In Auto mode the tool checks the first non-whitespace character. A leading { or [ that also parses as JSON means you pasted JSON and want YAML. Everything else is treated as YAML. Because JSON is a strict subset of YAML 1.2, a YAML parser accepts both — the first-character check disambiguates your intent. You can override it with the toggle.
  2. YAML → JSON. The input is parsed with loadAll so multi-document streams (separated by ---) are captured. Scalars resolve per the Core Schema: null/~/empty become JSON null, true/false become booleans, decimal/hex/octal integers and floats become numbers, and anything else is a string. Anchors and aliases are expanded and merge keys (<<) are resolved, because JSON has no reference mechanism. The structure is serialized with JSON.stringify at your chosen indent.
  3. JSON → YAML. The input is parsed with JSON.parse and re-emitted as YAML in block style (or inline flow style if you prefer), with key order preserved unless you turn on sorting.
  4. Validate. A parse failure never blanks the screen. The exception is caught and the first error is shown with its 1-based line and column plus a short snippet, so you can jump straight to it.
  5. Round-trip check.The output is re-parsed and deep-compared against the original structure. Identical means "round-trip verified". If a construct cannot survive — for example .inf or .nan, which JSON renders as null — the result is marked lossy and the affected path is named.

This same engine (js-yaml on the YAML 1.2 schema) powers the worked examples below, which reproduce exactly in the live tool.

YAML ↔ JSON type mapping

Every conversion rule the tool applies, drawn from the YAML 1.2.2 Core Schema and RFC 8259. The * on the infinity/NaN row marks a construct JSON cannot represent.

YAMLJSONNotes
null, ~, (empty)nullAll YAML null forms collapse to JSON null.
true / falsetrue / falseBoolean. Only the canonical lowercase forms in the Core Schema.
42, 0x2A, 0o5242Integers: decimal, hex (0x) and octal (0o) all resolve to a number.
3.14, 1e33.14, 1000Floats keep their numeric value.
.inf, -.inf, .nannull *JSON has no Infinity/NaN — these become null and are flagged as lossy.
"text", text"text"Any non-resolving scalar is a string; JSON always quotes it.
- a\n- b (block) / [a, b] (flow)[a, b]Both block and flow sequences become a JSON array.
key: val / {key: val}{"key": val}Block and flow mappings become a JSON object.
&anchor / *alias(expanded)JSON has no references — aliases are materialised into duplicated subtrees.
<<: *anchor (merge)(merged keys)Merge keys are resolved into the surrounding object.
doc1\n---\ndoc2[doc1, doc2]A multi-document stream becomes a JSON array of documents.
# comment(dropped)JSON has no comments; they are not preserved.

Worked examples

YAML → JSON, with an anchor, merge key and null

YAML
defaults: &d
  retries: 3
  timeout: 30
prod:
  <<: *d
  timeout: 60
  enabled: true
  region: ~
JSON
{
  "defaults": { "retries": 3, "timeout": 30 },
  "prod": {
    "retries": 3,
    "timeout": 60,
    "enabled": true,
    "region": null
  }
}
  1. &d defines the anchor { retries: 3, timeout: 30 }.
  2. prod merges it with <<: *d, then overrides timeout to 60.
  3. enabled: true stays a boolean; region: ~ resolves to null.
  4. The anchor is expanded (JSON has no references).

JSON → YAML, nested object and array

JSON
{ "name": "induwara",
  "tags": ["seo", "tools"],
  "meta": { "live": true, "rank": null } }
YAML
name: induwara
tags:
  - seo
  - tools
meta:
  live: true
  rank: null
  1. The object becomes a block mapping.
  2. The array becomes a block sequence with - markers.
  3. true stays boolean; null is emitted as null.
  4. Round-trip: re-parsing the YAML returns the original object.

Lossy edge case — .inf in YAML

YAML
bandwidth: .inf
samples: 1000
JSON
{
  "bandwidth": null,
  "samples": 1000
}
  1. .inf resolves to Infinity under the YAML Core Schema.
  2. JSON (RFC 8259) cannot represent infinity, so it becomes null.
  3. The tool still converts but marks the result lossy and names the path ($.bandwidth).
  4. samples: 1000 converts cleanly as an integer.

Frequently asked questions

Sources & references

Conversion rules were last cross-checked against the YAML 1.2.2 spec and RFC 8259 on 2026-06-25. The tool uses the js-yaml parser on the YAML 1.2 Core/Default schema.

Related tools

Rate this tool
Be the first to rate

Comments & feedback

Spotted a bug or want an improvement? Tell us — our team reviews every comment, and good ideas get built. Comments are public and anonymous.

Found a bug, edge case, or want to suggest an improvement?

Email me at [email protected] — most fixes ship within 24 hours.