Skip to content

YAML to JSON Converter

Paste YAML, get JSON instantly. Live conversion in your browser. K8s manifests, OpenAPI specs, helm values supported. 100% private, no upload.

No Tracking Runs in Browser Free
Options · 2 spaces
Indent
0 chars
JSON Output
0 lines
Reviewed for YAML 1.2 spec compliance, anchor/alias expansion, and multi-document handling correctness — Go Tools Engineering Team · May 4, 2026

What is JSON?

JSON (JavaScript Object Notation) is a lightweight, text-based data interchange format standardized as RFC 8259 and ECMA-404. It supports six data types — strings, numbers, booleans, null, arrays, and objects — with a strict, minimal syntax that virtually every programming language, API, and toolchain can parse natively. While YAML is the preferred format for human-written configuration files (Kubernetes manifests, GitHub Actions, Ansible playbooks, Helm values), JSON is the universal machine-readable format for APIs, automation scripts, and programmatic data processing.

Converting YAML to JSON is therefore one of the most common tasks in DevOps and backend development — you have a YAML config file but need JSON to feed into a REST API, query with jq, or process with JavaScript tooling.

This tool has four important differentiators compared to typical online converters:

**1. Multi-Document YAML Handling.** YAML supports multiple documents in a single stream separated by --- (the document start marker). Many real-world YAML files — including some Kubernetes manifests and Ansible playbooks — contain multiple documents. This tool uses parseAllDocuments from the eemeli/yaml library with { version: '1.2', merge: true } options and returns the first document as JSON, clearly communicating what was taken. If you need all documents, split on --- and convert each individually.

**2. Anchor and Alias Expansion.** YAML anchors (&name) and aliases (*name) allow reuse of data blocks — a powerful YAML feature with no JSON equivalent. This tool fully expands all anchors and aliases (including merge keys: <<: *anchor) so the JSON output contains complete, self-contained data without any references. This is always the correct transformation because JSON has no reference syntax. The expansion is handled safely by the eemeli/yaml library, which includes protection against circular references. Learn how this compares to the reverse direction at JSON to YAML Converter.

**3. Comment Loss — Educational Transparency.** YAML supports # comments, which are frequently used in Kubernetes manifests, Helm values, and Ansible playbooks to document intent. JSON has no comment syntax, so comments are permanently dropped during conversion. This is not a bug — it is a fundamental format difference. This tool makes this explicit so you know what to expect. If you need to preserve annotations, encode them as JSON fields (_comment keys or a dedicated metadata object) before converting, or keep YAML as the authoritative source. See our deep dive on YAML-JSON differences for more on format tradeoffs.

**4. 100% Browser-Based Privacy.** Your YAML data — which often contains Kubernetes secrets, database credentials, Helm values with passwords, and internal service configurations — never leaves your browser. No data is sent to any server. You can verify this in your browser's Network tab. After converting to JSON, you can validate and format the result with our JSON Formatter before using it downstream.

YAML's richness (comments, anchors, multi-document support, block scalars) makes it excellent for human-authored configuration files where readability and documentation matter. JSON's strictness and universality make it the better choice when a machine is the primary consumer. This converter bridges the two worlds: keep your configuration in YAML for human maintainability, convert to JSON when you need machine-readable interchange.

// Convert YAML to JSON in Node.js using the eemeli/yaml library
import { parseAllDocuments } from 'yaml';

const yamlString = `apiVersion: apps/v1
kind: Deployment`;

// parseAllDocuments handles multi-document YAML (--- separator)
// version: '1.2' ensures yes/no are strings, not booleans
// merge: true expands anchor/alias merge keys (<<: *anchor)
const docs = parseAllDocuments(yamlString, { version: '1.2', merge: true });

// Take the first document (skip additional --- blocks)
const json = JSON.stringify(docs[0].toJSON(), null, 2);

console.log(json);
// {
//   "apiVersion": "apps/v1",
//   "kind": "Deployment"
// }

Key Features

Live Conversion

JSON output updates instantly as you type or paste YAML — no Convert button needed. Large inputs (>200KB) automatically switch to manual mode to keep the browser responsive.

Indent 2 or 4 Spaces

Switch between 2-space and 4-space indentation for the JSON output. 2 spaces is standard for most tooling and APIs; 4 spaces matches some style guides and editor defaults.

Multi-Document Support

Handles YAML streams with multiple --- separated documents. The first document is converted to JSON and returned. Useful for Kubernetes multi-resource files and Ansible playbooks.

Anchor and Alias Expansion

Fully expands YAML anchors (&name) and aliases (*name), including merge keys (<<: *anchor). The JSON output contains complete, dereferenced data with no references — correct behavior since JSON has no equivalent.

100% Browser-Based Privacy

All conversion runs locally in your browser using JavaScript. Your YAML data — including secrets, credentials, and production configs — is never sent to any server, never logged, and never stored.

Handles K8s, Compose, Helm, and OpenAPI

Optimized for real-world DevOps use cases: Kubernetes manifests, Docker Compose stacks, Helm chart values, GitHub Actions workflows, OpenAPI specs, and Ansible playbooks — with examples for each.

Examples

Kubernetes Manifest

apiVersion: apps/v1
kind: Deployment
metadata:
  name: my-app
  namespace: production
  labels:
    app: my-app
    version: 1.0.0
spec:
  replicas: 3
  selector:
    matchLabels:
      app: my-app
  template:
    metadata:
      labels:
        app: my-app
    spec:
      containers:
        - name: my-app
          image: my-app:1.0.0
          ports:
            - containerPort: 8080
          resources:
            requests:
              memory: 64Mi
              cpu: 250m
            limits:
              memory: 128Mi
              cpu: 500m

Convert a Kubernetes Deployment manifest from YAML to JSON — useful for querying with jq, sending to the Kubernetes API, or feeding into Terraform and CI/CD pipelines

Docker Compose

version: '3.9'
services:
  web:
    image: nginx:1.25-alpine
    ports:
      - '80:80'
      - '443:443'
    environment:
      NGINX_HOST: example.com
      NGINX_PORT: '80'
    depends_on:
      - db
    restart: unless-stopped
  db:
    image: postgres:16-alpine
    environment:
      POSTGRES_DB: mydb
      POSTGRES_USER: admin
      POSTGRES_PASSWORD: secret
    volumes:
      - pgdata:/var/lib/postgresql/data
volumes:
  pgdata: {}

Convert a Docker Compose YAML to JSON for programmatic manipulation, feeding into automation scripts, or processing with JavaScript tooling

GitHub Actions Workflow

name: CI
on:
  push:
    branches:
      - main
  pull_request:
    branches:
      - main
jobs:
  build:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - name: Set up Node.js
        uses: actions/setup-node@v4
        with:
          node-version: '20'
          cache: pnpm
      - name: Install dependencies
        run: pnpm install --frozen-lockfile
      - name: Run tests
        run: pnpm test

Parse a GitHub Actions workflow YAML to JSON to query specific fields, validate structure, or integrate with APIs that consume JSON

OpenAPI Spec

openapi: 3.0.3
info:
  title: User API
  version: 1.0.0
  description: Manage application users
paths:
  /users:
    get:
      summary: List users
      operationId: listUsers
      parameters:
        - name: limit
          in: query
          schema:
            type: integer
            default: 20
      responses:
        '200':
          description: Success
          content:
            application/json:
              schema:
                type: array
                items:
                  $ref: '#/components/schemas/User'
  /users/{id}:
    get:
      summary: Get user
      operationId: getUser
      parameters:
        - name: id
          in: path
          required: true
          schema:
            type: string
      responses:
        '200':
          description: Success
components:
  schemas:
    User:
      type: object
      properties:
        id:
          type: string
        name:
          type: string
        email:
          type: string
          format: email

Convert an OpenAPI 3.0 spec from YAML to JSON for use with client code generators, API testing tools, or programmatic schema inspection

Helm values.yaml

replicaCount: 3
image:
  repository: my-app
  tag: 1.0.0
  pullPolicy: IfNotPresent
service:
  type: ClusterIP
  port: 80
ingress:
  enabled: true
  className: nginx
  hosts:
    - host: my-app.example.com
      paths:
        - path: /
          pathType: Prefix
resources:
  requests:
    memory: 64Mi
    cpu: 250m
  limits:
    memory: 128Mi
    cpu: 500m
autoscaling:
  enabled: false
  minReplicas: 1
  maxReplicas: 10
  targetCPUUtilizationPercentage: 80

Convert Helm chart values.yaml to JSON for analysis, generating reports, or feeding into tooling that expects JSON configuration

Ansible Playbook

- name: Configure web servers
  hosts: webservers
  become: true
  vars:
    http_port: 80
    max_clients: 200
  tasks:
    - name: Ensure nginx is installed
      ansible.builtin.package:
        name: nginx
        state: present
    - name: Start nginx service
      ansible.builtin.service:
        name: nginx
        state: started
        enabled: true
    - name: Copy nginx config
      ansible.builtin.template:
        src: nginx.conf.j2
        dest: /etc/nginx/nginx.conf
        owner: root
        group: root
        mode: '0644'
      notify:
        - Restart nginx
  handlers:
    - name: Restart nginx
      ansible.builtin.service:
        name: nginx
        state: restarted

Parse an Ansible playbook YAML to JSON for inspecting task structure, auditing configurations, or integrating with reporting pipelines

How to Use

  1. 1

    Paste Your YAML

    Enter or paste your YAML data into the input field above. You can also click 'Load example' to try a sample like a Kubernetes Deployment, Docker Compose file, or Helm values.yaml.

  2. 2

    See Live JSON Output

    JSON appears instantly in the output panel. Adjust Options (indent 2 or 4 spaces) to match your target tool's requirements.

  3. 3

    Copy or Download

    Click Copy to grab the JSON to your clipboard, or Download to save it as a .json file ready for jq, API calls, or any downstream tooling.

Common YAML Pitfalls

Tab Indentation

The YAML specification forbids tab characters for indentation — only spaces are allowed. If your YAML was written or copy-pasted from an editor that uses tabs, the parser will throw an error. Replace all tab indentation with spaces (2 or 4 spaces per level).

✗ Wrong
services:
	web:
		image: nginx:1.25-alpine
✓ Correct
services:
  web:
    image: nginx:1.25-alpine

Mismatched Indentation

YAML uses consistent indentation to define nesting. Mixing different numbers of spaces within the same block (e.g., 2 spaces at one level and 3 at another) causes parse errors. Each level must indent by the same number of spaces throughout the document.

✗ Wrong
metadata:
  name: my-app
   namespace: production
✓ Correct
metadata:
  name: my-app
  namespace: production

Unquoted Special Characters

Characters like :, #, &, *, {, }, [, ], |, >, !, and @ have special meaning in YAML. Using them unquoted in values can cause parse errors or unexpected behavior. Quote values that contain these characters with single or double quotes.

✗ Wrong
url: http://example.com:8080/api
tag: #latest
✓ Correct
url: 'http://example.com:8080/api'
tag: '#latest'

Anchor Cycles

YAML technically allows anchors that reference themselves (circular references), though this is rare in practice. A circular anchor causes the parser to enter an infinite expansion loop. The eemeli/yaml library detects and throws an error for circular anchors rather than hanging.

✗ Wrong
# Circular anchor (rare but possible)
base: &base
  parent: *base
✓ Correct
# Use explicit fields instead of circular references
base:
  parent: null

Multi-Document Confusion

YAML files with multiple --- separators contain multiple documents. This tool returns only the first document as JSON. If you expected data from a later document (after the second or third ---), it will not appear in the output. Split your YAML on --- and convert each section separately if you need all documents.

✗ Wrong
# Only the first document is converted
apiVersion: v1
kind: ConfigMap
---
apiVersion: v1
kind: Secret
✓ Correct
# Convert each document separately
apiVersion: v1
kind: ConfigMap

Comment Loss

YAML supports # comments but JSON does not. All YAML comments are permanently dropped during conversion — this is a fundamental format difference, not a tool limitation. If you need to preserve annotations in JSON, encode them as a dedicated field such as a _comment key or a metadata object.

✗ Wrong
# This comment will be lost
replicas: 3 # scale this up for production
✓ Correct
replicas: 3
_comment: scale this up for production

Common Use Cases

Kubernetes Manifest Analysis
Convert Kubernetes YAML manifests to JSON for querying with jq, sending to the Kubernetes REST API, processing in Terraform data sources, or feeding into CI/CD pipelines that expect JSON.
Docker Compose to JavaScript Tooling
Parse Docker Compose YAML to JSON to extract service definitions, image names, port mappings, and environment variables for use in automation scripts, dependency graphs, or Node.js tooling.
GitHub Actions API Integration
Convert GitHub Actions workflow YAML to JSON to validate structure programmatically, extract job and step definitions, or integrate with CI/CD APIs that accept JSON workflow specifications.
OpenAPI to Client Code Generation
Many code generators (openapi-generator, swagger-codegen, oazapfts) accept OpenAPI specs in either format. Convert your YAML spec to JSON when a tool specifically requires JSON input or when you need to inspect it with JSON Schema validators.
Helm Values Analysis
Convert Helm chart values.yaml to JSON to generate reports, compare values across environments, feed into policy enforcement tools, or process with automation that expects JSON configuration.
Config Migration to JSON-Based Tools
Migrate application configuration from YAML (common in infrastructure tools) to JSON for use in JavaScript environments, REST APIs, AWS AppConfig, Azure App Configuration, or any system that stores configuration as JSON.

Technical Details

YAML 1.2 Spec via parseAllDocuments with merge:true
YAML is parsed using the eemeli/yaml library (v2.8+, CVE-safe) via parseAllDocuments with { version: '1.2', merge: true }. The YAML 1.2 schema ensures bare strings like yes and no are treated as strings (not booleans), matching the current YAML specification. The merge: true option fully expands anchor/alias merge keys (<<: *anchor) so the JSON output contains complete, dereferenced data. Multi-document YAML (--- separated) returns the first document.
Anchor and Alias Expansion via Library
The eemeli/yaml library handles anchor (&name) and alias (*name) expansion safely, including circular reference detection. All aliased data blocks — including merge key expansions — are fully inlined in the JSON output. This is the correct transformation because JSON has no reference or anchor concept. The library's safe expansion prevents infinite loops from malformed YAML.
Browser-Based — No Upload, No Server
All processing happens entirely in your browser's JavaScript engine. No data is transmitted over the network at any point. Inputs larger than 200KB automatically switch from live mode to manual mode (requiring an explicit Convert click) to keep the browser responsive and prevent main-thread blocking during heavy serialization.

Best Practices

Use YAML 1.2-Compatible Syntax for Clean Conversion
Author your YAML using YAML 1.2 conventions — quote yes, no, on, off, y, and n string values explicitly (e.g., enabled: 'yes') to avoid ambiguity. This tool parses with the YAML 1.2 schema (so these are strings), but older tools in your pipeline may use YAML 1.1 (where they become booleans). Explicit quoting in the source YAML is the safest practice across all parsers.
Quote Large Numbers in YAML to Preserve Precision
JavaScript cannot represent integers larger than 2^53 - 1 (9007199254740991) exactly. Kubernetes fields like resourceVersion and uid are int64 on the server and can exceed this limit. In your YAML source, quote these values (resourceVersion: '9007199254740993') so the parser treats them as strings, which are then preserved exactly in the JSON output as string values.
Validate JSON Output Before Using in APIs
After converting YAML to JSON, validate the result before sending it to an API, storing it, or processing it programmatically. Use our JSON Formatter to confirm the structure is correct. This is especially important for Kubernetes API calls, OpenAPI specs, and any JSON Schema-validated payload, where a structural error causes a confusing rejection at the API layer rather than at the conversion step.
Separate Multi-Document YAML Before Converting
If your YAML file contains multiple --- separated documents and you need all of them as JSON, split the file on --- first and convert each document individually. This tool takes only the first document. A simple approach: split on '\n---\n' in your editor or with awk, then paste each section separately.
Use jq for Downstream JSON Processing
Once you have JSON from your YAML, jq is the fastest way to query and transform it from the command line. Combine this tool with jq: convert your YAML online, paste the JSON, then use jq '.spec.replicas' or jq '.services | keys' to extract exactly what you need. For batch processing of many files, use the yq CLI with -o json flag directly.

Frequently Asked Questions

How do I convert YAML to JSON online?
Paste your YAML into the input field above. The tool converts it to JSON instantly in your browser — no button click needed. You can adjust the output indentation (2 or 4 spaces) from the Options panel. Once the JSON appears in the output area, click Copy to grab it to your clipboard or Download to save it as a .json file. Everything runs locally — your data never leaves your device.
How does this tool handle multi-document YAML (--- separator)?
YAML supports multiple documents in a single stream, separated by --- (the document start marker). When you paste a multi-document YAML string, this tool uses parseAllDocuments from the eemeli/yaml library and returns the first document as JSON. The additional documents beyond the first are silently ignored. If you need to process all documents, split your YAML on --- and convert each section individually. The tool shows the first document's JSON so you can verify the result.
How are YAML anchors and aliases (&anchor and *alias) handled?
YAML anchors (&name) define a reusable block, and aliases (*name) reference it. This tool fully expands all anchors and aliases during parsing, so the output JSON contains the complete, dereferenced data. For example, if a YAML anchor defines a set of resource limits and multiple services alias it with merge keys (<<: *anchor), the JSON output shows every field explicitly inlined for each service. This is the correct behavior for JSON, which has no concept of references. The eemeli/yaml library handles anchor/alias expansion safely, including circular reference detection.
Are YAML comments preserved in the JSON output?
No. JSON does not support comments of any kind — no #, //, or /* */ syntax. When you convert YAML to JSON, all comments are permanently lost. This is a fundamental format difference, not a limitation of this tool. If you need to preserve annotations, consider encoding them as a dedicated JSON field (such as a _comment key) before converting, or keeping the YAML source as the authoritative version with comments. This tool clearly reflects the data as JSON without any comment approximation, which is the correct and standard behavior.
How do I use this tool with a Kubernetes manifest?
Paste your Kubernetes YAML manifest (from a .yaml file, kubectl get -o yaml output, or a Helm template) into the input field. The JSON output can then be queried with jq, sent directly to the Kubernetes REST API, used in Terraform data sources, or processed by any tooling that expects JSON. A common workflow is to convert YAML manifests to JSON to extract specific fields — for example: jq '.spec.replicas' on the JSON output to verify replica counts across deployments. The K8s Deployment example above shows a complete manifest you can load and modify.
How does this tool help with Docker Compose files?
Docker Compose files are YAML by convention. Converting them to JSON lets you process service definitions with JavaScript tooling, jq scripts, or any system that reads JSON. Common use cases include extracting all image names to build a dependency list, generating reports from a compose file, or feeding Compose configurations into CI/CD orchestration tools that accept JSON. Paste your compose.yaml into the input and the JSON output is immediately ready for downstream processing.
What is the difference between YAML 1.1 and YAML 1.2, and which does this tool use?
YAML 1.1 (the older spec, still used by PyYAML, Ansible, Ruby Psych, and many Kubernetes tools) treats bare strings like yes, no, on, off, y, and n as boolean true/false values. This caused the infamous Norway Problem where the ISO country code 'NO' was parsed as false. YAML 1.2 (the current spec, released in 2009) fixed this: all bare strings are strings, and only true/false are boolean. This tool uses the YAML 1.2 schema for parsing, meaning yes and no in your YAML input are preserved as the string values 'yes' and 'no' in the JSON output — not boolean true and false. This is the correct, modern behavior. If your YAML was originally authored for a YAML 1.1 parser and relied on yes/no as booleans, be aware the JSON output will treat them as strings.
Why does YAML forbid tab indentation?
The YAML specification explicitly forbids tab characters (\t) for indentation — only spaces are allowed. This is a deliberate design decision to avoid the ambiguity caused by inconsistent tab width across editors. If your YAML uses tabs for indentation (common when copying from text editors that auto-convert spaces to tabs), the YAML parser will throw a parse error. The fix is to replace all tab indentation with spaces. Most code editors have a setting to convert tabs to spaces (for example, 'Expand Tabs' in Vim, 'Insert Spaces' in VS Code). If you paste YAML and see a parse error mentioning 'tab' or 'indentation', this is almost always the cause.
Can large numbers lose precision when converting YAML to JSON?
Yes. This is a fundamental JavaScript limitation that affects all browser-based tools. JavaScript's IEEE 754 double-precision float can only represent integers exactly up to 2^53 - 1 (9007199254740991). YAML numbers larger than this — such as Kubernetes int64 fields like resourceVersion — will be silently rounded when the YAML parser hands them to JavaScript's number type. For example, the YAML value 9007199254740993 becomes 9007199254740992 in the JSON output. The safe workaround is to quote large numbers in your YAML source (resourceVersion: '9007199254740993') so the parser treats them as strings, which are then preserved exactly in JSON as string values.
How can I convert YAML to JSON on the command line?
The most popular approach uses yq (Mike Farah's version) and jq. Install yq: brew install yq on macOS or download from github.com/mikefarah/yq/releases for Linux. Then run: yq -o json input.yaml to convert a YAML file to JSON, or cat input.yaml | yq -o json - to pipe from stdin. For pretty-printed output: yq -o json input.yaml | jq . — this pipes the JSON through jq for consistent formatting. For a Python one-liner: python3 -c "import sys, json, yaml; print(json.dumps(yaml.safe_load(sys.stdin), indent=2))" < input.yaml. For multi-document YAML with yq: yq -o json '.[0]' input.yaml to extract only the first document as JSON.
Is my YAML data sent to any server when I use this tool?
No. All conversion happens entirely in your browser using JavaScript. Your YAML data is never transmitted over the network, never stored on any server, and never logged or analyzed. This makes the tool safe to use with Kubernetes secrets, database credentials, internal Helm values, API keys in config files, and any other sensitive infrastructure configuration. You can verify this by opening your browser's Network tab — you will see zero requests triggered by pasting YAML.
Is there a file size limit for YAML input?
There is no hard file size limit, but large inputs (over 200KB) automatically switch from live conversion to manual mode. In manual mode, a Convert button appears and conversion runs only when you click it — this prevents the browser's main thread from blocking on every keystroke. For very large YAML files (multi-megabyte), consider using command-line tools like yq for better performance. The tool efficiently handles typical real-world payloads like full Kubernetes namespace exports, large OpenAPI specs, and multi-service Helm chart values files.

Related Tools

View all tools →