YAML ⇄ JSON Converter Pro
High-fidelity, fast, and safe conversion with validation-ready pipeline
YAML ⇄ JSON Converter Pro
High-fidelity, fast, and safe conversion with validation-ready pipeline
Features
- Bidirectional YAML ↔ JSON conversion using the js-yaml library (YAML 1.2 compliant) — handles multi-document streams, anchors and aliases, tagged scalars, flow and block syntax
- Auto-detect mode sniffs whether pasted text is YAML or JSON and runs the conversion in the opposite direction, no manual mode switch needed
- Round-trip safety: JSON.parse → js-yaml.dump and js-yaml.load → JSON.stringify preserve types (number, boolean, null, string, array, object) without coercion
- Pretty/compact output controls: JSON indent (2/4 spaces, tab, or single-line) and YAML flow-vs-block style for the target format
- Multi-document YAML support: documents separated by `---` markers become a JSON array, JSON arrays with multiple objects can emit as multi-document YAML
- Error reporting includes line and column when js-yaml provides them — fix malformed YAML at the exact position instead of binary-searching for the bad indent
- One-click copy of converted output ready to paste into a config repo, Kubernetes manifest, or API request body
- Pure client-side: js-yaml runs in your browser, no network calls. Tool works offline once cached, safe for secrets that shouldn't leave your machine
How to use
- Paste either YAML or JSON into the input pane.
- With Auto-detect, the tool sniffs the format and converts to the other direction. Or pick the direction explicitly via the mode selector.
- Adjust output formatting: indent size, flow vs block YAML style.
- Click Convert. The result appears in the output pane.
- Click Copy to put the result on your clipboard.
- If the input is malformed, an inline error row shows the parser's message with line/column when available — fix and reconvert.
Tips & Best Practices
- For Kubernetes manifests, prefer block-style YAML output — kubectl and most operators expect that format.
- When converting to JSON for a REST API body, 2-space indent compact mode is the sweet spot.
- If the conversion shows surprising types (numbers as strings, etc.), check the YAML's quoting conventions; YAML's type-inference is the source of most "why is my data wrong" surprises.
- For CI configs, keep the canonical form as YAML (it's commenting-friendly) and convert to JSON only when a tool requires it.
- Pair with JSON Schema Validator: convert YAML to JSON here, then validate against your schema in the other tool.
FAQ
Are YAML anchors and aliases preserved when converting to JSON?
No — JSON has no equivalent of anchors (`&name`) and aliases (`*name`). js-yaml dereferences them when loading, so a YAML file with shared references becomes a JSON file with duplicated content. Round-tripping JSON → YAML won't reintroduce the anchors. If anchor preservation matters, keep the YAML source as your canonical form.
How are multi-document YAML streams handled?
YAML with `---` document separators becomes a JSON array — one element per document. JSON arrays can emit as multi-document YAML if every element is an object/array at the top level. Single-document YAML produces a JSON object/array as you'd expect.
What about YAML tags like !!timestamp or !!binary?
Standard YAML 1.2 tags are recognised by js-yaml: !!str, !!int, !!float, !!bool, !!null, !!map, !!seq, !!timestamp, !!binary. Timestamps round-trip as ISO 8601 strings in JSON (JSON has no native date type); binary tags decode to base64 strings. Custom tags need a registered constructor — not supported in this tool, use a YAML CLI for those cases.
Why does my YAML number become a string in JSON?
YAML's rules for distinguishing strings from scalars are stricter than people remember: `version: 1.10` is a float (1.1), but `version: "1.10"` is a string. If your YAML quoted a number you wanted as a number, drop the quotes; if it didn't quote but you wanted a string, add quotes. The Norway problem (`country: NO` parsed as boolean false) was fixed in YAML 1.2 but persists in 1.1 parsers — js-yaml here uses 1.2 by default.
How does the converter handle indentation in YAML output?
js-yaml dumps with 2-space indent by default; this tool exposes 2/4/tab selection. Block style (the default, newline-separated keys) is what most humans expect; flow style emits `{key: value}` JSON-like syntax that's compact but harder to read. Pick based on whether your YAML will be edited by humans.
Is anything sent to a server?
No. js-yaml is a JavaScript library that runs entirely in your browser. The conversion happens in the same tab that loaded the page; no network call is made when you click Convert.
Can I convert very large YAML files?
Yes for under ~10MB. Larger files work but block the UI thread during parse; for production-scale ETL of multi-megabyte YAML, run js-yaml in a Web Worker or use a Python/Go/Node CLI.
What if my YAML has comments — are they preserved?
No. JSON has no comment syntax. The YAML parser strips comments when loading; the dumper emits clean YAML without them when going back. If comments are critical (documenting a config), keep the original YAML — this tool is for format conversion, not for safe round-tripping with annotations.