What is YAML to JSON conversion?
YAML is human-friendly config, the format behind Kubernetes, CI pipelines, Ansible, and Docker Compose. JSON is machine-friendly and API-native. Converting lets you feed hand-authored config into tools and APIs that only speak JSON, or validate YAML against a JSON Schema. Anchors are expanded, merge keys resolved, and comments dropped since JSON has none.
Edge cases & gotchas
- Norway Problem: unquoted
NO,YES,ON,OFFparse as booleans. Quote them to preserve strings. - Leading zeros / versions:
01234may parse as a number and1.0becomes float1. Quote to keep as string. - Multi-document streams (
---): JSON has no multi-doc concept: output the first doc or a JSON array. - Comments lost:
#lines do not transfer. - Indentation-sensitive: tabs are invalid; inconsistent indent is a parse error.
- Explicit tags (
!!str, custom!Tag) may be coerced or dropped; key order isn't guaranteed.
YAML → JSON value mapping
| YAML | JSON |
|---|---|
~ / null / empty | null |
NO / OFF (unquoted) | false |
&anchor / *alias | inlined copy |
<<: *anchor | merged keys |
--- (multi-doc) | array / first doc |
How to use
- Paste YAML into the Input pane, or upload a
.yml/.yamlfile. - For multiple documents (
---), choose first-doc or JSON-array output. - Convert: js-yaml parses, resolves anchors and aliases, and emits JSON.
- Choose indentation (2 or 4 spaces) or minify.
- Copy the result or download it as
.json.
Examples
Config map → object
server: host: localhost port: 8080 ssl: true
{
"server": {
"host": "localhost",
"port": 8080,
"ssl": true
}
}Anchors, aliases & merge keys
defaults: &defaults adapter: postgres host: localhost development: <<: *defaults database: dev_db
{
"defaults": { "adapter": "postgres", "host": "localhost" },
"development": {
"adapter": "postgres",
"host": "localhost",
"database": "dev_db"
}
}The Norway Problem (type coercion)
country: NO
{ "country": false }
// quote it (country: "NO") to keep the stringFAQ
What is a YAML to JSON converter?
A tool that parses YAML (a superset of JSON) and re-serializes it as strict JSON.
Does YAML support comments, and do they survive?
YAML has # comments; JSON does not, so they are dropped.
How are anchors and aliases handled?
Expanded inline: the referenced node is copied into every location, and merge keys (<<) are flattened.
How do I convert YAML to JSON in Python, Node, or CLI?
yaml.safe_load + json.dumps (Python), js-yaml (Node), or yq -o=json (CLI).
Is my data processed locally?
Yes. js-yaml runs in your browser; DevTools → Network shows zero requests.
Can it handle multi-document YAML?
Yes, pick first-document, or emit a JSON array of documents. Need the reverse? Use JSON to YAML.