JSON Tools

JSON to YAML: Convert JSON for Docker, Kubernetes, and CI/CD

Convert JSON to YAML format for Kubernetes manifests, Docker Compose, GitHub Actions, and other config-file-heavy DevOps workflows.

Published January 15, 2025Updated June 1, 20255 min read

Try the free online tool

Runs entirely in your browser — no signup, no uploads.

Open Tool

YAML has become the configuration language of DevOps. Kubernetes manifests, Docker Compose files, GitHub Actions workflows, Ansible playbooks, Helm charts, and CI/CD pipelines are all written in YAML. But data often originates in JSON — from APIs, SDKs, CLI tools, and language runtimes. Converting between the two is a daily task for platform engineers and developers.

JSON and YAML are closely related: YAML is a superset of JSON, meaning every valid JSON document is also valid YAML. Converting JSON to YAML makes config files more human-friendly by replacing curly braces and quotation marks with indentation and bare strings, and by supporting comments.

This tool converts any valid JSON to idiomatic YAML instantly, preserving all data types and nesting exactly. Use it to bootstrap Kubernetes manifests from JSON spec exports, convert API schemas for documentation, or transform JSON fixtures into YAML test data.

What Is YAML and Why Is It Preferred for Config?

YAML (YAML Ain't Markup Language) is a human-friendly data serialization format. Its most distinctive feature is significant indentation: nesting is expressed through indentation rather than brackets, making it visually clean for deeply nested structures like Kubernetes resource specs.

YAML supports all the same data types as JSON (strings, numbers, booleans, null, arrays, objects) but adds several extras: multi-line strings (block scalars), comments (`#`), aliases and anchors for reusing values, and multiple documents in a single file separated by `---`. These features make YAML particularly well-suited for configuration files that humans edit frequently.

The trade-off is that YAML is more sensitive to formatting — indentation errors, tab characters (not allowed in YAML), and subtle whitespace differences can silently change meaning or break parsing. For data interchange between systems, JSON is safer. For human-maintained configuration, YAML is usually preferred.

  • JSON objects → YAML mappings (key: value pairs with indentation instead of braces)
  • JSON arrays → YAML sequences (items prefixed with `- `)
  • JSON strings → YAML bare strings (no quotes needed unless they contain special characters)
  • JSON booleans → YAML `true`/`false` (note: YAML also treats `yes`/`no`/`on`/`off` as booleans in YAML 1.1)
  • JSON null → YAML `null` or `~`

How to Use This Tool

Paste your JSON and get idiomatic YAML output immediately. The converter handles all type mappings automatically.

  1. 1

    Paste your JSON

    Enter any valid JSON — object, array, or any scalar value — into the input panel.

  2. 2

    Review the YAML output

    The tool converts and displays YAML with proper indentation. Strings that need quoting (those starting with special characters or resembling other YAML types) are quoted automatically.

  3. 3

    Adjust indentation

    Choose 2-space or 4-space indentation depending on the convention of your project (Kubernetes uses 2 spaces; some Ansible projects use 4).

  4. 4

    Add comments manually

    One advantage of YAML is comment support. After conversion, open the output in your editor and add `# comment` annotations to document sections.

  5. 5

    Copy or download

    Copy the YAML to clipboard or download as a `.yaml` file for direct use in your project.

Common Use Cases

JSON-to-YAML conversion comes up constantly in DevOps, infrastructure, and backend development workflows.

  • Kubernetes manifests — `kubectl` can export resources as JSON (`kubectl get deployment my-app -o json`); convert to YAML for storing in version control.
  • Helm chart values — convert JSON configuration exported from a tool into YAML values files for Helm deployments.
  • GitHub Actions workflows — convert a JSON-defined workflow or matrix into YAML for the `.github/workflows/` directory.
  • OpenAPI/Swagger specs — API specs exist in both JSON and YAML; convert to YAML for more readable documentation in editors like Swagger Editor.
  • Terraform variable files — convert JSON variable definitions to YAML `.tfvars` files for Terraform workspaces that accept YAML input.

Tips and Best Practices

YAML has some well-known pitfalls. Being aware of them saves hours of debugging.

  • Never use tabs in YAML — YAML prohibits tab characters for indentation. Always use spaces. Most editors have a setting to convert tabs to spaces automatically.
  • Watch out for YAML boolean gotchas — in YAML 1.1 (used by many tools), `yes`, `no`, `on`, `off`, `true`, `false` are all booleans. Country codes like `NO` (Norway) or `ON` (Ontario) need quoting to be treated as strings.
  • Use block scalars for multiline strings — YAML block scalars (`|` for literal, `>` for folded) are cleaner than JSON string escaping for multiline values like scripts or SQL.
  • Validate YAML after conversion — use `yamllint` or a Kubernetes dry-run (`kubectl apply --dry-run=client`) to check for syntax and structural errors.
  • Keep JSON as source of truth for APIs — use YAML only for human-maintained config files. For data exchanged between services, stick with JSON to avoid YAML parsing edge cases.

Frequently Asked Questions

Is YAML a superset of JSON?

Yes, in YAML 1.2 and later. Every valid JSON document is valid YAML, meaning a YAML parser can parse JSON directly. However, YAML 1.1 (used by many older tools) has minor differences in boolean handling. When in doubt, convert explicitly rather than relying on the superset relationship.

Why do some strings get quoted in the YAML output?

YAML auto-detects types based on value content. Strings like `true`, `null`, `1.0`, `2024-01-15` would be interpreted as boolean, null, float, or date — not strings — without quotes. The converter adds quotes to preserve the correct type from the original JSON.

Can I convert YAML back to JSON?

Yes. Since YAML is a superset of JSON, any YAML document can be parsed by a YAML parser and re-serialized as JSON. Use our YAML-to-JSON tool, or in the terminal: `python3 -c "import sys, yaml, json; print(json.dumps(yaml.safe_load(sys.stdin), indent=2))" < file.yaml`.

How do I convert Kubernetes JSON to YAML?

Run `kubectl get <resource> <name> -o json | python3 -m json.tool > raw.json` to export the JSON, then use this tool or `kubectl` itself: `kubectl get <resource> <name> -o yaml > manifest.yaml`. The `kubectl` method is the most reliable for Kubernetes-specific output.

What causes `yaml: found character that cannot start any token` errors?

This error usually means there is a tab character used for indentation (YAML requires spaces), or a special character like `{`, `}`, `:`, or `#` at the start of an unquoted string. The converter avoids these by quoting strings that contain special characters.

Should I store configuration in JSON or YAML in my repository?

For human-edited configuration files (CI/CD workflows, infrastructure manifests, Helm values), YAML is almost universally preferred because of its readability and comment support. For machine-generated or API-facing configuration, JSON is safer because it has fewer parsing edge cases.

json to yamlyamlkubernetesdockerdevops configuration

Ready to use this tool?

Free, instant, no account required. Runs entirely in your browser.

Open Tool

More JSON Tools Guides