YAML to JSON Converter

Convert YAML to JSON format. Handles all YAML features including anchors, multiline strings, and nested structures.

Input
Output

How to Use the YAML to JSON Converter

  1. Paste your YAML into the input panel on the left. This can be a Kubernetes manifest, a CI/CD workflow, a Docker Compose file, or any valid YAML document.
  2. Click “Convert to JSON” to parse the YAML and produce the equivalent JSON with proper indentation.
  3. Review the JSON output in the right panel. All YAML-specific features (anchors, multi-line strings, comments) are resolved into their JSON equivalents.
  4. Copy the result using the copy button. The JSON is ready to use in your application, API request, or configuration file.
  5. To go the other way, use the JSON to YAML converter to transform JSON back into YAML format.

What is YAML to JSON Conversion?

YAML (YAML Ain’t Markup Language) and JSON (JavaScript Object Notation) are both data serialization formats, but they serve different niches. YAML is popular for human-edited configuration files — Kubernetes manifests, GitHub Actions workflows, Ansible playbooks, and Docker Compose files all use YAML because its indentation-based syntax is easy to read and write. JSON, on the other hand, is the lingua franca of APIs, databases, and programmatic data exchange because every programming language has native JSON parsing support.

Converting YAML to JSON is a common task when you need to feed a YAML config file into an API that only accepts JSON, when you want to validate YAML data using JSON Schema, or when you need to process YAML data in a language or tool that lacks a YAML parser. This converter handles all standard YAML features — nested mappings, sequences, anchors, aliases, multi-line strings, and type coercion — producing clean, valid JSON output. If you need to validate the output further, try the JSON Formatter or generate types with the JSON to TypeScript converter.

Examples

1. Converting a Kubernetes YAML manifest

Kubernetes resources are defined in YAML. Converting to JSON is useful for API calls or programmatic manipulation:

# Input YAML:
apiVersion: apps/v1
kind: Deployment
metadata:
  name: web-server
  labels:
    app: web
spec:
  replicas: 3
  selector:
    matchLabels:
      app: web
  template:
    spec:
      containers:
        - name: nginx
          image: nginx:1.25
          ports:
            - containerPort: 80

JSON output:

{
  "apiVersion": "apps/v1",
  "kind": "Deployment",
  "metadata": {
    "name": "web-server",
    "labels": { "app": "web" }
  },
  "spec": {
    "replicas": 3,
    "selector": { "matchLabels": { "app": "web" } },
    "template": {
      "spec": {
        "containers": [
          {
            "name": "nginx",
            "image": "nginx:1.25",
            "ports": [{ "containerPort": 80 }]
          }
        ]
      }
    }
  }
}

2. Converting a GitHub Actions workflow

CI/CD workflows in .github/workflows/ are YAML. Convert to JSON to process them programmatically:

# Input YAML:
name: CI
on:
  push:
    branches: [main]
  pull_request:
    branches: [main]
jobs:
  test:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - run: npm install
      - run: npm test

The converter produces a JSON object with the same structure, replacing YAML’s indentation syntax with JSON braces and brackets.

3. Converting a Docker Compose file

Docker Compose files use YAML extensively. Converting to JSON can help when building tooling or validating configs:

# Input YAML:
version: "3.8"
services:
  app:
    build: .
    ports:
      - "3000:3000"
    environment:
      - NODE_ENV=production
      - DATABASE_URL=postgres://db:5432/app
    depends_on:
      - db
  db:
    image: postgres:16
    volumes:
      - pgdata:/var/lib/postgresql/data
volumes:
  pgdata:

The JSON output preserves all service definitions, port mappings, environment variables, and volume declarations.

Common Use Cases

  • Kubernetes API calls: The Kubernetes API accepts JSON. Convert your YAML manifests to JSON for kubectl API requests or programmatic cluster management.
  • CI/CD pipeline processing: Parse GitHub Actions, GitLab CI, or CircleCI configs as JSON for linting, validation, or automated modification.
  • JSON Schema validation: Validate YAML configuration files against a JSON Schema by converting the YAML to JSON first.
  • Cross-format tooling: Feed YAML config data into tools that only accept JSON input — REST APIs, database imports, or language-specific parsers.
  • Ansible to JSON: Convert Ansible playbooks or inventory files to JSON for processing in non-Python environments.
  • Configuration migration: Move from YAML-based config to JSON-based config when changing frameworks or platforms.
  • Debugging YAML syntax: If your YAML is not parsing correctly, converting to JSON can reveal the actual data structure the parser sees.

Frequently Asked Questions

Does it handle YAML anchors and aliases?

Yes. YAML anchors (&anchor) and aliases (*anchor) are fully resolved during conversion. The resulting JSON contains the expanded values everywhere the alias was referenced, since JSON has no equivalent of YAML’s anchor/alias mechanism.

What about multi-line strings?

All YAML multi-line string styles are supported: literal block scalars (|), folded block scalars (>), and their chomping variants (|-, |+, >-, >+). The converter preserves newlines in literal blocks and folds lines in folded blocks, matching the YAML specification.

Can it handle multiple YAML documents in one file?

The converter processes the first YAML document in the input. If your file contains multiple documents separated by ---, only the first document is converted. Split your file at the --- markers and convert each document separately.

What YAML features are not supported in JSON?

JSON cannot represent YAML-specific features like comments (they are stripped during conversion), custom tags (!!timestamp, !!binary), and complex mapping keys (objects as keys). The converter handles these gracefully — comments are removed, anchors are expanded, and standard tags are converted to their JSON equivalents.

Is there a maximum file size?

The tool runs entirely in your browser, so the limit depends on your device’s available memory. Most modern browsers handle YAML files up to 5-10 MB comfortably. For very large files, consider using a command-line tool like yq.

Does it preserve the order of keys?

Yes. The converter preserves the original key order from your YAML file in the JSON output. Keys appear in the same sequence as they do in the YAML source. If you want to sort keys alphabetically, use the JSON Sort tool on the output.

Is my data sent to a server?

No. All conversion happens entirely in your browser using JavaScript. Your YAML data never leaves your machine.

Privacy & How It Works

The YAML to JSON converter runs entirely in your browser. When you click Convert, the tool parses your YAML using a JavaScript YAML parser and serializes the result as formatted JSON — all locally in your browser tab. No data is transmitted to any server, no cookies track your usage, and nothing is stored after you close the tab. This makes it safe to convert sensitive Kubernetes secrets, CI/CD configs with tokens, and private infrastructure definitions. You can verify this by opening your browser’s Network tab. Other tools on JsonDevKit, including the JSON to YAML converter, JSON Schema Generator, and JSON Diff, work the same way.