Home › JSON to YAML Converter

JSON to YAML Converter Online

Instantly convert JSON to YAML with proper formatting. Free, private, no signup — your data stays in your browser.

JSON vs YAML: Side-by-Side Example

JSON:

{
  "name": "Alice",
  "age": 30,
  "active": true,
  "roles": [
    "admin",
    "editor"
  ],
  "address": {
    "city": "NYC",
    "zip": "10001"
  }
}

YAML:

name: Alice
age: 30
active: true
roles:
  - admin
  - editor
address:
  city: NYC
  zip: '10001'

YAML is 25% shorter and more readable — no braces, no quotes for most strings.

JSON to YAML Type Mapping

JSON YAML Notes
"string"stringQuotes omitted unless ambiguous
4242Same
true / falsetrue / falseSame (also yes/no in YAML)
nullnull or ~Both are valid YAML null
[1, 2, 3]- 1\n- 2\n- 3Block sequence style
{}Indented block mappingNo braces needed

Convert JSON to YAML in JavaScript

// Using js-yaml library (npm install js-yaml)
import yaml from 'js-yaml';

const jsonData = { name: 'Alice', age: 30, roles: ['admin', 'editor'] };
const yamlString = yaml.dump(jsonData);
console.log(yamlString);
// name: Alice
// age: 30
// roles:
//   - admin
//   - editor

Convert JSON to YAML in Python

import json, yaml  # pip install pyyaml

with open('data.json') as f:
    data = json.load(f)

with open('data.yaml', 'w') as f:
    yaml.dump(data, f, default_flow_style=False, allow_unicode=True)

# Or as a string:
yaml_str = yaml.dump(data, default_flow_style=False)
print(yaml_str)

Common YAML Use Cases

Frequently Asked Questions

Is all JSON valid YAML?

Yes. JSON is a valid subset of YAML 1.2. Any JSON file can be parsed by a YAML parser. However, YAML has additional features (comments, anchors, aliases, multi-line strings) that JSON does not support.

Why does YAML quote some strings but not others?

YAML quotes strings that could be misinterpreted as other types. For example, "10001" (a ZIP code) must be quoted in YAML because unquoted 10001 would be parsed as an integer. Similarly, "true", "null", and "yes" need quotes to be treated as strings.

Which should I use — JSON or YAML for config files?

YAML is preferred for config files that humans edit because it supports comments and is less noisy. JSON is preferred for programmatic config (like package.json) because it is stricter and easier to parse with any language. When in doubt for Kubernetes, CI/CD, or Docker — use YAML.

Convert JSON to YAML now

Free, instant, private — no signup required.

JSON vs YAML Syntax Comparison

YAML is a superset of JSON and is preferred for configuration files due to its readability. Converting between them is lossless for most data types.

Side-by-Side Comparison

# JSON                           # YAML
{                                name: Alice
  "name": "Alice",               age: 30
  "age": 30,                     active: true
  "active": true,                roles:
  "roles": ["admin","user"],       - admin
  "address": {                     - user
    "city": "London"             address:
  }                                city: London
}

YAML Features Not in JSON

FeatureYAML SyntaxJSON Equivalent
Comments# This is a commentNot in JSON
Multi-line strings| or > block scalarsJSON uses \n escapes
Anchors & aliases& and * for reuseJSON has no references
Explicit types!!int, !!str, !!boolJSON infers types
Bare stringsNo quotes needed usuallyJSON always needs quotes
Dates2024-01-01 (auto-parsed)JSON uses string format

Convert in Different Environments

# Python
import json, yaml
with open("data.json") as f:
    data = json.load(f)
with open("output.yaml", "w") as f:
    yaml.dump(data, f, default_flow_style=False)

# Node.js (js-yaml)
const yaml = require("js-yaml");
const data = JSON.parse(fs.readFileSync("data.json"));
fs.writeFileSync("output.yaml", yaml.dump(data));

# CLI
python3 -c "import sys,json,yaml; print(yaml.dump(json.load(sys.stdin)))" < in.json

Also useful: JSON to CSV | JSON to XML | JSON vs XML | JSON Formatter