YAML ⇄ JSON Converter

Both directions, live in browser, spec-conformant

{{ error }}

YAML or JSON?

JSON is more compact and universally available — great for APIs and machines. YAML is easier to read and write (indentation, comments) and is preferred for configuration files (Kubernetes, Docker Compose, Ansible, GitHub Actions). Both represent the same data types — so lossless conversion is possible (except comments are lost on YAML→JSON).

Common pitfalls

YAML has surprising edge cases: `no` and `off` are parsed as boolean false in YAML 1.1 (so a Norwegian language code loses its meaning). `1.0` is a number, `'1.0'` is a string. Time values like `12:00` get converted to seconds. For simple configs YAML is pleasant; for complex structures with many special characters JSON is safer.

YAML and JSON in Depth: Specs, Models, Conversion

JSON (RFC 8259 / ECMA-404) and YAML (YAML 1.2.2, yaml.org) are syntactically very different but represent the same data model: scalars, sequences (lists) and mappings (associative arrays). YAML is actually a superset of JSON — every valid JSON is valid YAML too. That makes round-trip conversion mathematically lossless for data, with one important exception: comments. YAML allows # comments, JSON does not. Going YAML → JSON loses comments — for configs that you commit, keep the YAML source.

In practice both formats dominate different territory: JSON is the lingua franca for REST/GraphQL APIs, logs, browser LocalStorage and npm's package.json. YAML is standard in Kubernetes manifests, Docker Compose, Ansible playbooks, GitHub Actions, GitLab CI and MkDocs. If you generate a deployment.yaml in a Helm chart programmatically, the workflow is often: build data in TypeScript/Python, feed it through the build as JSON, output YAML at the end — exactly what our converter does in the browser using js-yaml@4, a spec-conformant parser for YAML 1.2.

A crucial point for clean configs: YAML 1.2.2 has cured the infamous "Norway problem". In YAML 1.1, no, NO, off, OFF, yes, on were automatically parsed as booleans — the ISO code for Norwegian (no) lost its meaning. YAML 1.2 accepts only true and false as booleans. If you work with older tools (e.g. Ruby Psych 1.x or SnakeYAML 1.x), quote such values: language: "no".

How to Convert Between YAML and JSON

Conversion happens live in the browser. Follow these steps:

  1. Pick the direction: YAML → JSON e.g. to turn a Kubernetes manifest into an API payload, JSON → YAML for human-readable configs.
  2. Paste your source on the left. Watch the indentation in YAML — spaces only, no tabs, otherwise the parser reports "unexpected tab character".
  3. The output appears on the right. JSON is indented with two spaces; YAML uses two-space indentation and a line-width limit of 100 (so long strings are not aggressively wrapped).
  4. On errors the exact position appears below the field (line/column). Most common causes: tabs instead of spaces, missing :, unquoted values containing special characters like : # @ &.
  5. Copy the result via the clipboard icon. Tip: for CI pipelines you can use the same js-yaml library as a build step — behavior is identical.

Real-World Examples

Here are typical conversions you encounter in practice:

  • Simple map: name: Anna\nage: 29 becomes {"name":"Anna","age":29}. Note that 29 is automatically interpreted as a number.
  • List in block syntax: roles:\n - editor\n - author becomes "roles":["editor","author"]. The inline form roles: [editor, author] produces the same.
  • Multi-line string: description: |\n Hello\n World is preserved as "Hello\nWorld" with newlines. With > the newlines would be replaced by spaces.
  • Kubernetes manifest: a deployment in YAML with apiVersion: apps/v1, kind: Deployment and nested spec.template.spec.containers becomes a well-structured JSON tree — ideal as an API body for kubectl --raw.
  • GitHub Actions workflow: name: CI\non: [push]\njobs: ... becomes {"name":"CI","on":["push"],"jobs":{...}}. Heads up: in YAML 1.1 on is a boolean — js-yaml@4 (YAML 1.2) correctly keeps it as a string key.

Limits, Edge Cases and Security Notes

YAML is powerful but tricky. First: indentation. YAML accepts only spaces, never tabs for indentation. Mixed indentation or a single tab in a 200-line file breaks the whole parse. Configure your editor with expandtab width 2. Second: anchors and aliases. &name and *name enable reuse of structures — when exporting to JSON, aliases are expanded (referenced sub-structures are duplicated into two separate objects), which makes the JSON noticeably bigger. Third and security-critical — YAML code execution: older YAML parsers (PyYAML <5, SnakeYAML <2) allowed remote code execution via !!python/object/apply or !!javax.script.ScriptEngineManager tags. js-yaml@4 (in the browser) and safe_load (Python) forbid custom tags by default — still, never parse YAML from untrusted source with the unsafe load(). Fourth: Norway problem. YAML 1.1 turns nofalse. js-yaml@4 is YAML 1.2 and correctly keeps it as string — but be careful if the consumer speaks YAML 1.1 (some cloud CI systems still do). Fifth: comment loss. YAML → JSON drops every # comment. Keep the YAML source as the single source of truth and JSON only as a machine format.

Frequently Asked Questions about YAML/JSON Conversion

Is anything lost when I convert YAML to JSON?
Data is not lost — scalars, sequences and mappings are identical in both. What is lost are comments (JSON has none) and sometimes anchors/aliases (expanded into duplicated objects). Keep the YAML source for reviews and documentation.
What is the YAML "Norway problem"?
In YAML 1.1, no, off, yes, on were auto-cast to booleans — the ISO language code for Norwegian (no) lost its string identity. YAML 1.2 (used by js-yaml@4) fixed this. With older parsers, quote them: language: "no".
Why do I get "unexpected tab character" while parsing?
YAML accepts only spaces for indentation. A single tab — often introduced by an editor default or copy-paste from a terminal — instantly breaks the parse. Configure your editor with expandtab width 2 or run yamllint in CI.
Is it safe to parse YAML from the internet?
With modern parsers (js-yaml@4, PyYAML safe_load, SnakeYAML 2.x) yes — they ignore custom tags like !!python/object/apply. With old versions, YAML parsing was a remote code execution vector. Never use yaml.load() without explicit safe mode on untrusted input.
How do I handle comments on a YAML → JSON → YAML round trip?
JSON has no comments, so they vanish on the first step. Workarounds: a pseudo key "_comment":"…", JSONC on the consumer side, or a build pipeline that keeps the YAML source and deploys JSON only as a generated artifact — the most common and cleanest approach.
Are my configs stored anywhere?
No. js-yaml runs as a JavaScript library in the browser; conversion happens locally. CalcSI sees neither content nor size. The copy button uses the native navigator.clipboard API — no server round trip.

Related Tools

  • JSON Formatter — Beautify, minify and validate for JSON snippets — perfect after YAML conversion.
  • CSV to JSON — Convert tabular data into JSON arrays for ETL and reporting pipelines.
  • JSON Editor — Tree view, schema validation and JSONPath/JMESPath queries for deeper structural analysis.