YAML to JSON conversion transforms data written in YAML (YAML Ain't Markup Language) into JSON (JavaScript Object Notation). Both formats represent structured data as key-value pairs, sequences, and nested objects, but they differ in syntax. YAML uses indentation and minimal punctuation, while JSON uses braces, brackets, and mandatory quoting. Converting between the two is a common task when moving configuration data between systems that expect different formats.
YAML was designed for human readability. It supports comments, multiline strings, anchors, and aliases, none of which exist in JSON. When you convert YAML to JSON, these YAML-specific features are resolved: anchors are expanded inline, comments are discarded, and multiline blocks become escaped strings. The output is valid JSON that any JSON parser can read.
The YAML 1.2 specification explicitly defines JSON as a subset of YAML, meaning every valid JSON document is also valid YAML. The reverse is not true. YAML documents that use comments, anchors, or complex keys have no direct JSON equivalent and must be simplified during conversion. This tool handles that conversion automatically, producing clean, well-formatted JSON from any valid YAML input.
Converting YAML to JSON by hand is error-prone, especially with deeply nested structures or multiline values. A browser-based converter gives you the result instantly and catches YAML syntax errors before they reach your application.
⚡
Convert instantly in your browser
Paste your YAML and get formatted JSON output in milliseconds. No CLI tools to install, no build step, no dependencies to manage.
🔀
Handle any valid YAML structure
Supports nested mappings, sequences, multiline strings (literal and folded blocks), anchors, aliases, merge keys, and all YAML 1.2 scalar types.
🔒
Keep your data private
All parsing runs locally in your browser using JavaScript. Your YAML content is never sent to a server, making it safe for configuration files that contain credentials or internal paths.
📋
Copy or adjust the output format
Switch between 2-space and 4-space indentation. Copy the JSON result to your clipboard with one click for direct use in code, API requests, or config files.
YAML to JSON Use Cases
Frontend Development
Convert YAML configuration files from a design system or CMS into JSON for consumption by JavaScript bundlers, REST APIs, or i18n libraries that require JSON input.
Backend Engineering
Transform Spring Boot application.yml or Rails database.yml into JSON to feed into deployment scripts, API gateways, or services that only accept JSON configuration.
DevOps and CI/CD
Convert docker-compose.yml, GitHub Actions workflows, or Kubernetes manifests to JSON for validation tools, policy engines like OPA, or debugging with jq.
QA and Testing
Turn YAML test fixtures into JSON payloads for API testing tools like Postman, Insomnia, or automated test suites that expect JSON request bodies.
Data Engineering
Convert YAML-formatted pipeline definitions (Airflow, dbt, Dagster) to JSON for schema validation, programmatic manipulation, or integration with metadata catalogs.
Learning and Documentation
Quickly see how YAML structures map to their JSON equivalents when studying configuration formats or writing documentation.
YAML to JSON Type Mapping Reference
Every YAML data type maps to a specific JSON type during conversion. The table below shows each YAML construct alongside its JSON output. Understanding these mappings helps you predict how your YAML data will look after conversion and avoid surprises with types like booleans or null values.
YAML Type
YAML Syntax
JSON Output
Mapping
name: Alice
{ "name": "Alice" }
Sequence
- apple\n- banana
["apple", "banana"]
String
greeting: hello world
"hello world"
Integer
count: 42
42
Float
ratio: 3.14
3.14
Boolean
active: true
true
Null
value: null
null
Multiline (|)
bio: |\n Line one\n Line two
"Line one\nLine two\n"
Folded (>)
note: >\n A long\n paragraph
"A long paragraph\n"
Anchor/Alias
&default\n <<: *default
Resolved inline (no $ref)
YAML vs JSON Syntax
YAML and JSON represent the same data model but with different syntax rules. The differences below explain why some YAML features — like comments and anchors — have no JSON equivalent.
YAML
Uses indentation for nesting (no braces). Supports comments with #. Strings usually don't need quotes. Allows multiline values with | (literal) and > (folded) block scalars. Supports anchors (&name) and aliases (*name) for reuse. Under YAML 1.2, only true and false are recognized as boolean values; older YAML 1.1 parsers also accepted yes, no, on, and off, but these are treated as plain strings in YAML 1.2.
JSON
Uses braces and brackets for nesting. No comment syntax. All strings must be double-quoted. No multiline string literals — use \n escape sequences instead. No anchor or alias mechanism. Boolean values are strictly lowercase true and false. All keys must be quoted strings. Trailing commas are invalid.
Code Examples
Below are working examples for converting YAML to JSON programmatically. Each example parses a YAML string and outputs formatted JSON.
# Convert a YAML file to JSON with yq
yq -o=json config.yaml > config.json
# Pipe YAML into yq for one-off conversion
echo "name: demo" | yq -o=json
# → { "name": "demo" }
# Python one-liner (no extra install on most systems)
python3 -c "import yaml, json, sys; print(json.dumps(yaml.safe_load(sys.stdin), indent=2))" < config.yaml
Frequently Asked Questions
Is YAML a superset of JSON?
Yes, as of YAML 1.2 (published in 2009). Every valid JSON document is also valid YAML. The YAML specification was intentionally updated to ensure full JSON compatibility. However, the reverse is not true — YAML features like comments, anchors, and unquoted keys have no JSON equivalent.
What happens to YAML comments during conversion?
Comments are discarded. JSON has no comment syntax, so any lines starting with # in your YAML input are lost during conversion. If you need to preserve comments, keep the original YAML file as the source of truth and generate JSON from it whenever needed.
How are YAML anchors and aliases handled?
Anchors (&name) and aliases (*name) are resolved during parsing. The alias is replaced with a full copy of the anchored data. The resulting JSON contains no references — all values are expanded inline. Merge keys (<<: *name) are resolved the same way.
Can YAML to JSON conversion lose data?
For data values, no. All YAML scalar types (strings, numbers, booleans, null) have direct JSON equivalents. What is lost: comments, tag directives, anchor names, and the distinction between block and flow style. If your YAML relies on custom tags (!!python/object, !!timestamp), those are resolved to plain values or may cause a parse error depending on the parser.
Why does my YAML boolean 'yes' become a string in JSON?
This tool uses js-yaml v4, which follows YAML 1.2 boolean resolution. Only true and false (any case) are recognized as booleans. Values like yes, no, on, and off are treated as plain strings and appear as quoted strings in the JSON output. If you see unexpected string values where you expected booleans, switch to true or false in your YAML source.
What is the maximum YAML file size this tool can handle?
The tool runs in your browser, so the limit depends on your device's available memory. In practice, files up to several megabytes convert without issues. For very large files (50 MB+), a CLI tool like yq or a Python script with PyYAML will be more reliable because they can stream data instead of loading everything into memory at once.
How do multiline YAML strings convert to JSON?
YAML has two multiline block scalar styles. Literal blocks (|) preserve line breaks as \n characters in the JSON string. Folded blocks (>) replace single line breaks with spaces, turning multiple lines into a single paragraph. Both styles append a trailing newline by default, which you can strip with the chomping indicator (|- or >-).