Skip to main content
Developer Tools June 26, 2026 · 6 min read

What Is YAML and How to Convert It to JSON

YAML appears in Docker Compose files, GitHub Actions workflows, Kubernetes manifests, Ansible playbooks, and thousands of other config files. It's designed to be readable by humans — but its indentation-based syntax trips up developers regularly. This guide explains YAML and how to convert it to and from JSON.

What Is YAML?

YAML stands for YAML Ain't Markup Language (a recursive acronym). It's a data serialisation format — like JSON and XML — but designed to be significantly more readable by humans.

Here's the same data in JSON and YAML:

JSON

{
  "name": "Alice",
  "age": 28,
  "active": true,
  "tags": ["dev", "admin"],
  "address": {
    "city": "Jakarta",
    "country": "Indonesia"
  }
}

YAML

name: Alice
age: 28
active: true
tags:
  - dev
  - admin
address:
  city: Jakarta
  country: Indonesia

YAML Syntax Essentials

Indentation

YAML uses spaces (never tabs) to denote nesting. Two spaces per level is the convention. Indentation errors are the most common cause of YAML parse failures.

Key-value pairs

key: value — separated by a colon and a space. The space after the colon is required.

Lists

Items start with a dash and space: - item. Lists can be inline: [item1, item2].

Strings

Usually don't need quotes. Use quotes when the value contains special characters like :, #, or starts with a number you want treated as a string.

Comments

Start with #. Everything from # to end of line is ignored. JSON has no comment support — a key YAML advantage.

Booleans and nulls

true/false (lowercase) for booleans. null or ~ for null values.

YAML vs JSON: When to Use Each

Feature YAML JSON
Human readability Excellent Moderate
Comments Supported Not supported
Parsing strictness Loose (can cause surprises) Strict
Use in APIs Rare Standard
Use in config files Very common Common
Error-prone Indentation errors common Syntax errors are obvious

How to Convert YAML to JSON

Use our YAML to JSON converter to paste YAML and get valid, formatted JSON output instantly — and convert back in the other direction.

In Python

import yaml, json

with open('config.yaml') as f:
    data = yaml.safe_load(f)

json_str = json.dumps(data, indent=2)
print(json_str)

In JavaScript (Node.js)

import { load } from 'js-yaml'; // npm install js-yaml
import { readFileSync } from 'fs';

const yaml = readFileSync('config.yaml', 'utf8');
const data = load(yaml);
console.log(JSON.stringify(data, null, 2));

Convert YAML ↔ JSON instantly