Menu

How-To Guide JSON · YAML · DevOps March 2026 ⏱ 8 min read

How to Convert JSON to YAML Online: Guide With Examples

YAML is the standard for Kubernetes, Docker Compose, Ansible, and GitHub Actions. When your data is in JSON, converting it manually means rewriting the entire structure. Here is a faster way.

YAML has become the standard configuration format in the DevOps world. Kubernetes, Docker Compose, Ansible, GitHub Actions, GitLab CI: all of these tools expect YAML. But data frequently originates in JSON format, from APIs, databases, or tools that export JSON. Converting manually means rewriting the entire structure, introducing indentation errors along the way. This guide shows exactly how the conversion works, with real examples for the tools you actually use.

Why YAML for Configuration Files?

YAML was designed for human readability. It replaces JSON's braces, brackets, and commas with clean indentation and colons. For files that developers read and edit regularly, which describes every DevOps configuration file, this makes a meaningful practical difference.

Here is the same configuration written in both formats:

JSON — 16 lines, lots of punctuation
{ "service": { "name": "api-gateway", "port": 8080, "replicas": 3, "healthCheck": { "path": "/health", "interval": "30s" }, "environment": [ "production", "eu-west" ] } }
YAML — 9 lines, no punctuation noise
service: name: api-gateway port: 8080 replicas: 3 healthCheck: path: /health interval: 30s environment: - production - eu-west

The YAML version has no brackets, no commas, no quotes around most values, and no closing braces. It reads cleanly from top to bottom, exactly what you want in a configuration file you review before every deployment.

JSON
16
lines for this config
YAML
10
lines for the same config
JSON
{ } [ ]
brackets required
YAML
none
brackets required

How JSON Maps to YAML

The conversion follows four consistent rules. Understanding them helps you predict what the output will look like and verify it is correct:

JSON
{ "key": { } }
Nested object with braces
YAML
key:
  nested:
Indented mapping, no braces
JSON
["a", "b", "c"]
Array with square brackets
YAML
- a
- b
- c
Sequence items with dash prefix
JSON
"name": "Alex"
String with double quotes
YAML
name: Alex
Scalar, quotes usually not needed
JSON
true / false / 42
Booleans and numbers
YAML
true / false / 42
Written directly, no quotes needed
⚡ When YAML does need quotes

Most values do not need quotes in YAML, but some do. Strings that look like booleans (yes, no, on, off), strings containing colons, and strings starting with special characters all need to be quoted to prevent parser misinterpretation. A converter handles this automatically.

Converting for Specific DevOps Tools

Each DevOps tool has its own YAML structure conventions. Here are real examples of JSON configurations converted to the YAML format each tool expects:

☸️
Kubernetes Deployment
Kubernetes expects YAML manifests with apiVersion, kind, metadata, and spec fields. Convert your JSON deployment config and apply it directly with kubectl apply.
apiVersion: apps/v1 kind: Deployment metadata: name: api-gateway spec: replicas: 3 template: spec: containers: - name: api image: api:latest
🐳
Docker Compose
Docker Compose reads docker-compose.yml. Convert your service definitions, volume mounts, environment variables, and port mappings from JSON to the YAML format Docker Compose expects.
version: "3.9" services: api: image: api:latest ports: - "8080:8080" environment: - NODE_ENV=production volumes: - ./data:/app/data
GitHub Actions
Workflow files in .github/workflows/ must be YAML. Convert trigger definitions, job configurations, and step sequences from JSON to the YAML workflow format.
name: Deploy on: push: branches: - main jobs: deploy: runs-on: ubuntu-latest steps: - uses: actions/checkout@v4
📦
Ansible
Ansible uses YAML for all playbooks, variable files, and inventory configurations. Convert your JSON variable definitions and task structures to Ansible-compatible YAML.
# Variable file (vars.yml) app_name: api-gateway app_port: 8080 deploy_env: production allowed_hosts: - localhost - 10.0.0.0/8

Step-by-Step: Using the Converter

The entire conversion takes under 30 seconds. Everything runs in your browser, no data is sent to any server.

  1. Paste your JSON into the input field at the StackDevTools JSON to YAML Converter.
  2. Click Convert to YAML. If your JSON has a syntax error, it is flagged with the line number before conversion begins.
  3. Review the YAML output. Verify the indentation is correct for your use case, and check that array items are mapped to the element names your tool expects.
  4. Click Copy and paste directly into your configuration file.
🔍 Validate your JSON before converting

Before converting, paste your JSON into the JSON Formatter to validate the syntax and review the structure. Clean, well-structured JSON produces clean YAML. Any syntax error in the input will be flagged immediately. Better to catch it here than debug a malformed config file later.

The Most Important YAML Warning

YAML is sensitive to indentation in a way that JSON is not. In JSON, whitespace is ignored and extra spaces have no effect. In YAML, a single extra or missing space can change the data structure entirely, silently, without throwing an error. This is YAML's most dangerous property.

⚠ Subtly broken YAML
service: name: api-gateway config: port: 8080 debug: true ← 3 spaces instead of 4 ← debug is now at the WRONG level
✓ Correct indentation
service: name: api-gateway config: port: 8080 debug: true ← 4 spaces, same level as port ← debug is correctly under config
⚠ Always verify indentation after converting

After converting from JSON to YAML, always review the output structure carefully, especially for deeply nested configurations. A single misaligned line places a key at the wrong level of the hierarchy with no error message. If a Kubernetes deployment or Docker Compose service is behaving unexpectedly, indentation is the first thing to check.

Frequently Asked Questions

Is the conversion reversible? Can I convert YAML back to JSON?

Yes. YAML is a superset of JSON, meaning all valid JSON is valid YAML. Converting JSON to YAML and back to JSON preserves all data. The structure is the same; only the representation changes. This means you can use either format as the source of truth and convert as needed.

Why does YAML sometimes parse my string as a boolean?

YAML parsers interpret certain unquoted values as booleans. yes, no, true, false, on, and off are parsed as boolean values in some YAML parsers. If you need these as strings, they must be quoted: "yes". A good converter handles this automatically by quoting ambiguous values.

Does the converter handle deeply nested JSON?

Yes. The converter handles nested objects and arrays to any depth, producing correctly indented YAML that preserves the full hierarchy. Complex Kubernetes manifests with multiple levels of nesting convert accurately.

Is my data safe when I use this tool?

Yes. All conversion happens directly in your browser using JavaScript. Your JSON data is never sent to any server, never stored, and never accessible to us or any third party. This matters particularly when converting configuration files that may contain API keys, database credentials, or other sensitive values.

What is the difference between JSON and YAML?

JSON uses curly braces, square brackets, commas, and double-quoted strings. It is compact and fast to parse, ideal for API communication. YAML uses indentation and colons, supports comments, and requires no brackets or quotes for simple values. It is more readable, ideal for configuration files edited by developers. See our full JSON vs XML vs YAML comparison for a detailed breakdown.

Free browser-based tools

Convert JSON to YAML instantly

Validate JSON, convert to YAML or XML, and compare outputs. All free, all in your browser, no data ever leaves your device.

From JSON to YAML in Seconds

The conversion from JSON to YAML is mechanical and consistent, the same four rules applied every time. What makes it error-prone when done manually is YAML's indentation sensitivity: one misplaced space can put a key at the wrong level with no error to warn you. A converter eliminates that risk entirely.

For the DevOps tools that dominate modern infrastructure, Kubernetes, Docker Compose, Ansible, GitHub Actions, YAML is not optional. Having a reliable way to convert JSON configurations into valid, correctly-indented YAML is a practical everyday utility, not a niche capability.

Paste your JSON, convert, verify the indentation, and copy. Your Kubernetes manifest or Docker Compose file is ready in under 30 seconds.