JSON ↔ YAML — Free Online Tool

Convert JSON to YAML and YAML to JSON. Bidirectional converter, validator, formatter. Support for anchors, arrays, nested objects. Config files, Kubernetes.

Use this free online JSON ↔ YAML directly in your browser. No signup required, no data leaves your device. Part of Utilier — a collection of 133+ developer utilities.

What is JSON to YAML Converter (Bidirectional, Validator, Formatter)?

JSON to YAML converter transforms between JSON (JavaScript Object Notation) and YAML (YAML Ain't Markup Language) formats. Bidirectional: JSON → YAML (human-readable config), YAML → JSON (API consumption). Supports: nested objects, arrays, strings, numbers, booleans, null, comments (YAML only), anchors/aliases (YAML only), multi-line strings (YAML folded/literal). Validates syntax (detect errors before conversion), formats/prettifies output (indentation, spacing). Use cases: configuration files (Docker Compose, Kubernetes, CI/CD: YAML for readability, JSON for APIs), data exchange (convert YAML config to JSON for JavaScript parsing), API responses (YAML → JSON for consumption), documentation (JSON schema → YAML for readability).

  • JSON format: {"key": "value", "array": [1, 2, 3]}. Compact, machine-readable. Uses: APIs (REST responses), config files (package.json, tsconfig.json), data storage. Strict syntax (quoted keys, no trailing commas).
  • YAML format: key: value\narray:\n - 1\n - 2\n - 3. Human-readable (no braces, indentation-based). Uses: config files (Docker Compose, Kubernetes manifests, CI/CD: .gitlab-ci.yml, .github/workflows), Ansible playbooks.
  • YAML advantages: No braces/quotes (cleaner), comments (#), multi-line strings (| for literal, > for folded), anchors/aliases (&anchor, *alias: DRY configs). Easier to read/write manually.
  • JSON advantages: Stricter syntax (fewer errors), native JavaScript support (JSON.parse()), faster parsing, ubiquitous (APIs, databases, browsers). Machine-friendly.
  • Conversion: JSON → YAML: adds indentation, removes braces/quotes, preserves structure. YAML → JSON: adds braces/quotes, removes comments (JSON doesn't support), flattens anchors/aliases.

Why use json yaml?

Different tools prefer different formats. YAML for config (readable), JSON for APIs (parseable).

  • Config readability (JSON → YAML): JSON config: {"services": {"web": {"image": "nginx", "ports": ["80:80"]}}}. YAML: services:\n web:\n image: nginx\n ports: [80:80]. YAML = easier to read/edit (Docker Compose, Kubernetes).
  • API consumption (YAML → JSON): YAML config file → convert to JSON → parse in JavaScript (JSON.parse()). Example: YAML CI config → JSON for API. JavaScript natively parses JSON (not YAML, need library).
  • Version control (YAML for configs): YAML diffs cleaner (indentation changes clear). JSON diffs = braces, commas (noisy). Git: YAML config changes easier to review. Use YAML for human-edited files.
  • Tooling compatibility: Kubernetes: YAML manifests (kubectl apply -f). Terraform: JSON or HCL. Docker Compose: YAML. CI/CD: YAML (.gitlab-ci.yml, GitHub Actions). Convert between formats for tool compatibility.
  • Validation before deployment: Convert YAML → JSON, validate with JSON schema. Catch errors (missing keys, wrong types) before deploying config. Kubernetes: validate YAML manifest → JSON → schema check.
  • Documentation (JSON schema → YAML): JSON schema (technical) → YAML (readable documentation). API docs: JSON response → YAML example (easier to read). Use YAML for human-facing docs, JSON for machine validation.

When to use json yaml

Use whenever need to convert between JSON and YAML formats.

  • Converting config files (Docker Compose, Kubernetes: YAML ↔ JSON).
  • API development (YAML config → JSON for JavaScript parsing).
  • CI/CD pipelines (convert between .gitlab-ci.yml, .github/workflows/config.json).
  • Documentation (JSON schema → YAML examples for readability).
  • Validation (YAML → JSON → schema validation).
  • Data exchange (import YAML, export JSON for APIs).
  • Tool migration (tool A uses JSON, tool B uses YAML: convert configs).
  • Learning (compare JSON/YAML side-by-side, understand differences).

How to use json yaml

Paste JSON or YAML, convert to opposite format, copy result.

  1. Paste input: JSON: {"key": "value", "array": [1, 2, 3]}. Or YAML: key: value\narray: [1, 2, 3]. Or upload file (.json, .yaml, .yml). Auto-detects format (braces = JSON, indentation = YAML).
  2. Validate syntax: Tool checks for errors: missing braces, incorrect indentation, unquoted strings. Shows error line/column: 'Line 3: Expected comma'. Fix errors before conversion.
  3. Convert: Click 'Convert to YAML' or 'Convert to JSON'. Instant conversion (client-side). JSON → YAML: removes braces, adds indentation. YAML → JSON: adds braces, quotes keys.
  4. Configure options (optional): Indentation: 2 spaces (default), 4 spaces, tabs. Quote style (JSON): single, double. Inline arrays (YAML): [1, 2, 3] vs multi-line. Sort keys alphabetically.
  5. View output: Right pane shows converted output. Syntax highlighting (keys, values, strings, numbers). Formatted/prettified (readable indentation).
  6. Copy or download: Copy to clipboard (one-click). Or download: .json file (JSON output), .yaml/.yml file (YAML output). Use in config files, APIs, documentation.
  7. Validate YAML features: YAML → JSON: comments removed (JSON doesn't support). Anchors/aliases flattened (&anchor, *alias → repeated values). Multi-line strings converted (| → \n).

Key features

  • Bidirectional conversion: JSON ↔ YAML. Auto-detects input format (braces = JSON, indentation = YAML). One-click swap (convert back and forth). Preserves structure (nesting, arrays, types).
  • Syntax validation: Real-time error detection. JSON: missing braces, trailing commas, unquoted keys. YAML: incorrect indentation, tab/space mixing, invalid anchors. Shows error line/column.
  • Formatting/prettifying: JSON: indentation (2/4 spaces, tabs), sorted keys, trailing newline. YAML: consistent indentation, array style (inline vs multi-line), quote style (single/double/none).
  • YAML features support: Comments (# comment): preserved in YAML, removed in JSON conversion. Anchors/aliases (&anchor, *alias): flattened to repeated values in JSON. Multi-line strings (|, >): converted to \n in JSON.
  • Large file handling: Handles files up to 10MB. Streams large JSON/YAML (no browser freeze). Progress indicator for conversions >1MB. Efficient parsing (not regex-based).
  • Copy/download: Copy to clipboard (formatted output). Download as: .json (JSON), .yaml or .yml (YAML). File naming: input.json → input.yaml, config.yaml → config.json.
  • Diff view (optional): Side-by-side comparison: JSON (left) vs YAML (right). Highlights differences (added, removed, changed). Useful for understanding conversion (what changed?).

Common use cases

  • Docker Compose (YAML to JSON): docker-compose.yml (YAML) → convert to JSON for programmatic parsing (Node.js, Python). Or validate with JSON schema. JSON for APIs, YAML for manual editing.
  • Kubernetes manifest (YAML to JSON): deployment.yaml → convert to JSON → validate with Kubernetes API schema. Or manipulate in JavaScript (kubectl equivalent). kubectl uses YAML, APIs use JSON.
  • CI/CD config (.gitlab-ci.yml to JSON): .gitlab-ci.yml (YAML) → JSON for GitLab CI API. Or convert JSON CI config (CircleCI) to YAML (GitHub Actions). Cross-platform CI/CD migration.
  • API documentation (JSON to YAML): JSON API response → YAML example (more readable in docs). Example: {"user": {"name": "John", "age": 30}} → user:\n name: John\n age: 30. Cleaner docs.
  • Config file migration: Tool A config (JSON) → Tool B config (YAML). Example: tsconfig.json → equivalent YAML for different build tool. Or package.json → YAML for alternative package manager.
  • OpenAPI spec (YAML to JSON): OpenAPI spec (swagger.yaml) → JSON for tooling (Postman, API clients). Or JSON OpenAPI → YAML for manual editing (comments, readability).

Examples

JSON to YAML and YAML to JSON conversion examples.

Simple object (JSON to YAML)

{\n "name": "John",\n "age": 30,\n "active": true\n}
name: John\nage: 30\nactive: true

Braces removed, keys unquoted. Indentation preserved. Types maintained (number 30, boolean true).

Nested object (YAML to JSON)

user:\n name: John\n address:\n city: NYC\n zip: 10001
{\n "user": {\n "name": "John",\n "address": {\n "city": "NYC",\n "zip": 10001\n }\n }\n}

Indentation → braces. Keys quoted. Structure preserved (nesting maintained).

Array (JSON to YAML)

{\n "items": ["apple", "banana", "cherry"]\n}
items:\n - apple\n - banana\n - cherry

Array converted to YAML list (- item). Or inline: items: [apple, banana, cherry] (configurable).

YAML comments (lost in JSON conversion)

# Database config\nhost: localhost\nport: 5432 # PostgreSQL default
{\n "host": "localhost",\n "port": 5432\n}

Comments removed (JSON doesn't support). Workaround: use _comment key or separate documentation.

YAML anchors/aliases (flattened in JSON)

defaults: &defaults\n timeout: 30\njob1: *defaults\njob2: *defaults
{\n "defaults": {"timeout": 30},\n "job1": {"timeout": 30},\n "job2": {"timeout": 30}\n}

Anchor (&defaults) flattened. Alias (*defaults) expanded to repeated values. JSON has no reference concept.

Technical reference

JSON and YAML format specifications and conversion rules:

JSON syntax
Objects: {"key": "value"}. Arrays: [1, 2, 3]. Strings: "text" (double quotes). Numbers: 123, 3.14. Booleans: true, false. Null: null. No comments. No trailing commas. Keys must be quoted.
YAML syntax
Objects: key: value (indentation-based). Arrays: - item (dash + space) or [1, 2, 3] (inline). Strings: unquoted (text), single ('text'), double ("text"). Comments: # comment. Trailing commas ok.
Indentation (YAML)
Spaces only (2 or 4 spaces per level). NO TABS (YAML spec prohibits). Mixing tabs/spaces = parse error. Nested objects: indent child keys. Consistent indentation critical.
Data types
String: text, 'text', "text" (YAML), "text" (JSON). Number: 123, 3.14 (both). Boolean: true/false (both). Null: null (JSON), null/~ (YAML). Date: 2024-01-15 (YAML), "2024-01-15" (JSON string).
Multi-line strings (YAML)
Literal (|): preserves newlines (|\n line 1\n line 2). Folded (>): folds newlines to spaces (>\n long text). JSON: no multi-line (use \n: "line 1\nline 2").
Comments
YAML: # comment (anywhere). JSON: no comments (not in spec). YAML → JSON: comments removed. Workaround: _comment key (JSON) or # (YAML).
Anchors/aliases (YAML)
Anchor: &anchor (defines reusable value). Alias: *anchor (references anchor). Example: defaults: &defaults\n timeout: 30\njob: <<: *defaults. JSON: flattens (repeats values, no references).
Conversion: JSON → YAML
Remove: braces {}, brackets [] (keep inline arrays if short). Unquote: keys (key: not "key":). Add: indentation (2/4 spaces). Preserve: structure, types. Example: {"a": 1} → a: 1.
Conversion: YAML → JSON
Add: braces {}, brackets []. Quote: keys ("key":). Remove: comments (#), anchors/aliases (flatten). Convert: multi-line strings (| → \n). Example: a: 1 → {"a": 1}.
Edge cases
YAML: yes/no/on/off = booleans (convert to true/false). Numbers: 0x10 = hex (16), 010 = octal (8) in YAML. JSON: no hex/octal (use decimal). Dates: YAML auto-detects (2024-01-15), JSON treats as string.

Common mistakes to avoid

Using tabs in YAML (parse error)

Why it happens: YAML spec prohibits tabs (only spaces). Mixing tabs/spaces = inconsistent indentation (parse error: 'found tab character'). Editors auto-convert tabs (confusing).

How to avoid it: Use spaces only (2 or 4 per level). Configure editor: 'Indent using spaces' (not tabs). Validate YAML (tool detects tabs). Convert tabs to spaces before parsing.

Expecting comments to survive JSON conversion (lost)

Why it happens: JSON doesn't support comments (not in spec). YAML → JSON: comments removed. Information lost (config notes, TODOs). JSON with // comments = non-standard (some parsers fail).

How to avoid it: Accept comment loss in JSON. Or use _comment key: {"_comment": "note", "key": "value"}. Or separate documentation. Keep YAML as source (JSON for consumption).

Not quoting YAML strings with special chars (parse error)

Why it happens: YAML: unquoted strings ok (value: text). But special chars (colon :, dash -, brackets []) need quotes. value: text:more = parse error (: detected as key). value: 'text:more' = ok.

How to avoid it: Quote strings with: colons (:), dashes (-), brackets ([]), braces ({}), quotes (', "), hash (#). Or use double quotes always: "text". Validator shows errors.

Assuming YAML booleans same as strings (auto-conversion)

Why it happens: YAML: yes, no, on, off, true, false = booleans (auto-detected). 'no' (string) vs no (boolean false). country: no → {"country": false} (unexpected). Should be: country: 'no' (Norway code).

How to avoid it: Quote strings that look like booleans: 'yes', 'no', 'on', 'off', 'true', 'false'. Or use explicit !!str tag: !!str no. Check converted JSON (ensure types correct).

Inconsistent indentation in YAML (parse error or wrong nesting)

Why it happens: YAML = indentation-sensitive. 2 spaces vs 4 spaces vs 3 spaces (mixed) = parse error or wrong nesting. key:\n child: value (3 spaces) → indentation error. Must be consistent (2 or 4).

How to avoid it: Choose indentation: 2 spaces (common) or 4 spaces. Configure editor (auto-indent). Use formatter (prettier, yamlfmt). Validate before conversion (tool shows indentation errors).

Frequently asked questions

What is the difference between JSON and YAML?

JSON: machine-readable (braces, quoted keys), no comments, strict syntax. YAML: human-readable (indentation, unquoted keys), comments (#), flexible. JSON for APIs, YAML for configs. Both represent same data (convertible).

Can I convert YAML comments to JSON?

No, JSON doesn't support comments (not in spec). YAML → JSON: comments removed. Workaround: _comment key ({"_comment": "note"}) or separate documentation. Keep YAML as source of truth.

What happens to YAML anchors/aliases in JSON?

Flattened. Anchor (&anchor) and alias (*anchor) → repeated values in JSON. Example: &defaults, *defaults → two copies of same object. JSON has no reference concept (no pointers).

Why does my YAML parse fail?

Common errors: tabs (use spaces only), inconsistent indentation (2 vs 4 spaces mixed), unquoted special chars (value: text:more → quote: 'text:more'), missing space after colon (key:value → key: value). Use validator.

Can I use JSON with comments?

Non-standard. JSON spec: no comments. Some parsers support // or /* */ (JSONC, JSON5), but not universally supported. Better: use YAML (comments native) or _comment keys. Standard JSON = no comments.

Should I use spaces or tabs in YAML?

Spaces only (YAML spec prohibits tabs). Use 2 or 4 spaces per indentation level. Tabs = parse error ('found tab character'). Configure editor: 'Indent using spaces'.

How do I handle multi-line strings?

YAML: literal (|) preserves newlines, folded (>) folds to spaces. Example: text: |\n line 1\n line 2. JSON: use \n: {"text": "line 1\nline 2"}. YAML → JSON: | and > convert to \n.

References

Privacy and availability

  • Runs entirely in your browser — zero server processing
  • No signup or account required
  • Works offline once loaded
  • Fast, lightweight, no external dependencies
  • Available as a browser extension for Chrome and Firefox