{}JSONLint.app

Paste your YAML below to convert it to JSON:

Loading...

Why Convert YAML to JSON?

While YAML is great for human-readable configs, JSON is the standard for APIs, data interchange, and programmatic manipulation. Converting YAML to JSON lets you use config data in applications and services.

Example Conversion

YAML:

server:
  host: localhost
  port: 8080
  ssl: true
database:
  connection: postgres://localhost/mydb
  pool_size: 10

JSON:

{
  "server": {
    "host": "localhost",
    "port": 8080,
    "ssl": true
  },
  "database": {
    "connection": "postgres://localhost/mydb",
    "pool_size": 10
  }
}

YAML Features Supported

YAML FeatureJSON Equivalent
Mappings (key: value)Objects
Sequences (- item)Arrays
Inline arrays [a, b, c]Arrays
Multi-line strings (|, >)Strings with newlines
true/yes/ontrue
null/~null

Common Use Cases

  • API integration — Convert YAML configs to JSON for REST API calls
  • Kubernetes debugging — Get JSON output for kubectl commands
  • Config validation — Validate YAML structure using JSON Schema
  • Data processing — Parse YAML files in languages with better JSON support
  • Documentation — Generate JSON examples from YAML source files

YAML Gotchas

YAML has some surprising behaviors that affect conversion:

The Norway Problem

# YAML interprets these as booleans!
countries:
  - NO    # false
  - YES   # true

Solution: Quote values that look like booleans: "NO"

Numbers vs Strings

version: 1.0   # Number 1.0
version: "1.0" # String "1.0"
zip: 01234     # Octal number!
zip: "01234"   # String "01234"

Programmatic Conversion

JavaScript (Node.js)

const yaml = require('js-yaml');
const fs = require('fs');

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

Python

import yaml
import json

with open('config.yaml') as f:
    data = yaml.safe_load(f)
    
json_string = json.dumps(data, indent=2)
print(json_string)

Command Line (with yq)

# Convert YAML file to JSON
yq -o=json config.yaml > config.json

# Or pipe from stdin
cat config.yaml | yq -o=json

Pro Tips

  • 💡 Watch indentation — YAML is whitespace-sensitive. Inconsistent indentation causes parse errors.
  • 💡 Comments are lost — JSON doesn't support comments, so YAML comments won't transfer.
  • 💡 Validate the output — Use the JSON Validator to ensure correct JSON syntax.

Related Tools

Common Mistakes & Pro Tips

  • Every valid JSON document is already valid YAMLYAML 1.2 is a strict superset of JSON, so pasting JSON into a YAML parser works and round-trips cleanly. This is why JSON-to-YAML is lossless, while the reverse can lose YAML-only features like comments and anchors.
  • Anchors and aliases get expanded, comments get droppedAn anchor (&base) referenced by an alias (*base) is resolved into a full copy of that value in the JSON, so shared structure is duplicated rather than linked. Comments (# ...) have no JSON equivalent and are discarded entirely during conversion.
  • Indentation must be spaces, never tabsYAML forbids tab characters for indentation and relies on consistent spaces to define nesting. A single stray tab causes a parse error, and mixing indentation widths can silently change which key a value belongs to.
  • The Norway problem: unquoted booleans and nullsIn YAML 1.1 (still used by many parsers), bare words like no, off, yes, and on parse as booleans, so a country code NO can become false, and ~ or empty means null. Quote ambiguous scalars ("NO", "3.10") to force them to stay strings.
  • Multi-document streams only convert one documentA YAML file can contain several documents separated by ---, but a single JSON value can't hold all of them at once. Converters typically take the first document or require you to wrap them, so split multi-doc files or expect only the first to appear.

Frequently Asked Questions

How do I convert YAML to JSON?

Paste your YAML and it is parsed into an in-memory structure, then serialized as JSON. Mappings become objects, sequences become arrays, and scalars become strings, numbers, booleans, or null. Comments and formatting are not preserved because JSON has no place for them.

Are YAML comments kept in the JSON?

No. JSON has no comment syntax, so all # comments are stripped during conversion. If you need to retain notes, move them into an actual data field before converting, such as a "_comment" key.

What happens to YAML anchors and aliases?

They are fully resolved: each alias is replaced by a deep copy of the anchored value, so the JSON output contains the expanded data with no references. This can make the JSON larger than the YAML if the same block was reused many times.

Why did my value like 'NO' or 'yes' turn into a boolean?

Older YAML 1.1 parsers interpret several unquoted words (yes/no, on/off, true/false) as booleans, and a bare ~ as null. Wrap such values in quotes — "NO" — to guarantee they remain strings in the JSON.

Can I convert a file with multiple YAML documents?

A standard YAML stream separates documents with ---, but JSON represents a single value, so typically only the first document is converted. To convert all of them, split the file at the --- markers and convert each piece, or combine them into one top-level list first.

Does my YAML get uploaded for conversion?

No. The YAML is parsed in your browser and the JSON is generated locally, so nothing is sent to a server. That makes it safe for config files like Kubernetes manifests or CI pipelines that may include internal hostnames or secrets.