OhMyApps
Back to Blog
Tools Developer YAML JSON Tutorial

YAML to JSON Converter: Parse Configuration to Data

3 min read By OhMyApps

YAML is the go-to format for configuration files — Kubernetes manifests, Docker Compose files, CI/CD pipelines, and Ansible playbooks all use it. But when you need to send that data to an API or process it programmatically, JSON is often required.

Why Convert YAML to JSON?

While YAML is great for humans to read and write, JSON is the universal data interchange format. Common reasons to convert:

  • API requests: Most REST APIs expect JSON request bodies
  • Programmatic processing: JSON parsers are faster and available in every language
  • Validation: JSON Schema validators need JSON input
  • Storage: Databases and key-value stores often use JSON
  • Debugging: Seeing the explicit structure helps catch YAML indentation errors

YAML Syntax Basics

If you’re coming from JSON, here are the key YAML concepts:

Key-Value Pairs

name: John Doe
age: 30
active: true

Becomes:

{ "name": "John Doe", "age": 30, "active": true }

Nested Objects

YAML uses indentation (spaces, never tabs) to indicate nesting:

database:
  host: localhost
  port: 5432
  credentials:
    username: admin
    password: secret

Lists

Items prefixed with a dash become JSON arrays:

languages:
  - JavaScript
  - Python
  - Go

Becomes:

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

Mixed Structures

servers:
  - name: web-1
    port: 8080
    tags:
      - production
      - frontend
  - name: api-1
    port: 3000
    tags:
      - production
      - backend

Common YAML Pitfalls

Indentation Errors

YAML is whitespace-sensitive. Mixing spaces and tabs, or using inconsistent indentation, will cause parse errors. Always use spaces (2 or 4) consistently.

Unquoted Strings

Some values in YAML have special meaning:

# These are NOT strings — they're booleans!
enabled: yes    # true
disabled: no    # false
flag: on        # true

# These need quotes to be strings
enabled: "yes"
version: "1.0"

The Norway Problem

Country codes like NO (Norway) are interpreted as boolean false in YAML 1.1. Always quote values that could be ambiguous:

country: "NO"    # String "NO", not false

Multiline Strings

YAML supports multiline strings with | (preserves newlines) and > (folds into one line):

description: |
  This is a
  multiline string.

summary: >
  This will be
  folded into one line.

How to Use Our YAML to JSON Tool

  1. Paste your YAML content in the left panel
  2. Select your preferred JSON indentation (2 or 4 spaces, or compact)
  3. View the JSON output instantly in the right panel
  4. Copy the result with one click

The converter handles nested objects, arrays, multiline strings, comments (which are stripped in JSON), and common YAML data types.

Tips

  • If the conversion fails, check your YAML indentation — it must use spaces, not tabs
  • Comments in YAML (# comment) are removed during conversion since JSON doesn’t support comments
  • Boolean values like yes, no, on, off are converted to true/false
  • Numeric strings that should remain strings need quotes in YAML

Real-World Examples

Kubernetes Manifest

apiVersion: apps/v1
kind: Deployment
metadata:
  name: my-app
  labels:
    app: my-app
spec:
  replicas: 3

Converts to structured JSON ready for kubectl API calls or programmatic deployment tools.

GitHub Actions Workflow

name: CI
on: [push, pull_request]
jobs:
  test:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - run: npm test

Convert to JSON when building CI/CD tooling or migrating between platforms.


Try our free YAML to JSON converter to transform your configuration files instantly.

Try Ghost Image Hub

The Chrome extension that makes managing your Ghost blog images a breeze.

Learn More