How to Convert YAML to JSON Online

YAML is designed for humans. JSON is designed for machines. But most APIs speak JSON, which means DevOps engineers working with Kubernetes configs, Ansible playbooks, or Docker Compose files frequently need to cross the bridge between the two formats.

How YAML and JSON relate

YAML is a superset of JSON — any valid JSON document is also valid YAML. The two formats represent the same underlying data model: objects (key-value pairs), arrays (ordered lists), and scalar values (strings, numbers, booleans, null). The difference is purely in how they express structure:

ConceptYAMLJSON
Object/mapIndented key: value pairs{ "key": "value" }
Array/sequence- item with dash prefix["item"]
StringUnquoted or quotedAlways double-quoted
NumberUnquoted literalUnquoted literal
Booleantrue / false (or yes/no)true / false
Nullnull or ~null
Comments# commentNot supported

Example: basic key-value pairs

Input YAML:

name: John Smith
age: 30
active: true
email: john@example.com

Output JSON:

{
  "name": "John Smith",
  "age": 30,
  "active": true,
  "email": "john@example.com"
}

Notice that YAML doesn't require quotes around strings, while JSON always uses double quotes. The converter handles this automatically.

Example: sequences (arrays)

YAML sequences use a dash (-) prefix. Each dashed item becomes a JSON array element:

Input YAML:

skills:
  - JavaScript
  - Python
  - Go

Output JSON:

{
  "skills": [
    "JavaScript",
    "Python",
    "Go"
  ]
}

Example: nested objects

YAML uses indentation to express nesting. Each indented block becomes a nested JSON object:

Input YAML:

user:
  name: Jane
  address:
    city: London
    country: UK
  roles:
    - admin
    - editor

Output JSON:

{
  "user": {
    "name": "Jane",
    "address": {
      "city": "London",
      "country": "UK"
    },
    "roles": [
      "admin",
      "editor"
    ]
  }
}

Kubernetes example

A common real-world use case: converting a Kubernetes deployment manifest to JSON for use in an API call or Terraform resource:

Input YAML:

apiVersion: apps/v1
kind: Deployment
metadata:
  name: my-app
  namespace: default
spec:
  replicas: 3
  selector:
    matchLabels:
      app: my-app

Output JSON:

{
  "apiVersion": "apps/v1",
  "kind": "Deployment",
  "metadata": {
    "name": "my-app",
    "namespace": "default"
  },
  "spec": {
    "replicas": 3,
    "selector": {
      "matchLabels": {
        "app": "my-app"
      }
    }
  }
}

What gets lost in the conversion

YAML supports some features that JSON cannot represent:

For standard configuration files (Kubernetes, Docker, Ansible), the conversion is lossless.

Convert YAML to JSON instantly

Paste any YAML document and get clean, formatted JSON output. Handles Kubernetes manifests, Docker Compose files, Ansible playbooks, and any valid YAML. Free, private, no signup required.

Open YAML to JSON Converter

Frequently Asked Questions

Can I convert Kubernetes YAML to JSON?

Yes. Kubernetes manifests are standard YAML and convert cleanly to JSON. The Kubernetes API itself accepts both formats — JSON is the wire format underneath.

Does YAML to JSON preserve data types?

Yes. YAML integers and floats become JSON numbers, YAML booleans become JSON booleans, and YAML null becomes JSON null. Strings without quotes in YAML are quoted in JSON output.

What happens to YAML comments?

Comments are discarded. JSON has no comment syntax, so there is nowhere to put them. If you need to preserve documentation, consider keeping the YAML source alongside the JSON output.