YAML to JSON Converter
Runs locallyTurn YAML into JSON — anchors and merge keys resolved, multi-document files supported.
YAML
JSON
{"defaults": {"restart": "unless-stopped","logging": {"driver": "json-file"}},"services": {"api": {"restart": "unless-stopped","logging": {"driver": "json-file"},"image": "ghcr.io/example/api:1.4.2","ports": ["8080:8080"],"environment": {"FEATURE_FLAG": "on","REGION": "NO"}},"worker": {"restart": "unless-stopped","logging": {"driver": "json-file"},"image": "ghcr.io/example/worker:1.4.2","command": ["node","worker.js"]}}}- Line 13: "on" is a string here, but YAML 1.1 parsers (PyYAML, SnakeYAML, go-yaml v2) may read it as a boolean. Quote it to be safe.
- Line 14: "NO" is a string here, but YAML 1.1 parsers (PyYAML, SnakeYAML, go-yaml v2) may read it as a boolean. Quote it to be safe.
Converting YAML means resolving everything YAML adds to JSON
YAML has features JSON lacks. Anchors (&name) label a node and aliases (*name) repeat it; the <<: merge key copies a map into another, which is how Compose and CI files share defaults. Comments disappear, because JSON has nowhere to put them. A file can also hold several documents separated by ---, as kubectl manifests often do. The converter expands every alias and merge into full copies, drops comments, and returns multiple documents as a JSON array, or only the first if you untick the option.
The harder part is types. This converter follows YAML 1.2, where only true and false are booleans and 0755 is the decimal number 755. Many tools still use YAML 1.1 rules: PyYAML, Ruby, SnakeYAML in Spring Boot and go-yaml v2 read yes, no, on and off as booleans and 0755 as octal 493. When the input contains such a plain value, a warning names the line, so you can quote it and get the same result everywhere. See the YAML 1.2 specification for the full rules.
Errors are reported with a line and column, usually for indentation that does not line up or an unclosed or {. Once the JSON looks right, [query it with JSONPath or format it for a request body.
YAML with an anchor, a merge and two documents
base: &b image: nginx:1.27 restart: always web: <<: *b ports: ["80:80"] --- kind: Second
JSON array
[
{
"base": { "image": "nginx:1.27", "restart": "always" },
"web": { "image": "nginx:1.27", "restart": "always", "ports": ["80:80"] }
},
{ "kind": "Second" }
]The merge key copies image and restart into web, and the second document becomes the second array item.
Where people get caught
on, off, yes and no
Here they are strings, as YAML 1.2 says; in PyYAML or Spring they are booleans. The warnings list each one — quote it if the value must be a string.
Octal-looking numbers
file_mode: 0755 is 755 in YAML 1.2 and 493 in YAML 1.1. Write 0o755 for YAML 1.2 octal, or quote it.
Anchors inflate the output
Every alias becomes a full copy, so a small YAML file with shared defaults can become a much larger JSON file. That is expected.
Indentation with tabs
YAML does not allow tabs for indentation; the error points at the first one. Replace them with spaces.
About YAML to JSON conversion
How it works in 4 steps · 4 common use cases · 4 questions answered
About YAML to JSON conversion
How it works in 4 steps · 4 common use cases · 4 questions answered
How it works
- 1.Paste or drop YAML; the JSON updates as you type.
- 2.Choose the indent, or minified output.
- 3.Decide whether several documents become an array or only the first is kept.
- 4.Read the YAML 1.1 warnings, then copy or download the .json file.
Common use cases
- •Sending a Kubernetes manifest to an API that takes JSON
- •Checking what a Compose file with anchors really contains
- •Feeding YAML config into jq or a JSON Schema validator
- •Debugging a CI pipeline that reads a value differently than expected
FAQ
Are comments kept?
No. JSON has no comment syntax, so comments are dropped. Keep the YAML as the source of truth if the comments matter.
How are multiple documents handled?
Documents separated by --- become items of a JSON array. Untick the option to convert only the first document.
Why is "on" a string here but true in my app?
This converter follows YAML 1.2, where only true and false are booleans. Your app probably uses a YAML 1.1 parser. Quote the value so both agree.
Are anchors and merge keys supported?
Yes. Aliases are replaced with copies of the anchored node and <<: merges are applied, so the JSON contains the final values.
Related tools
- JSON to YAMLConvert JSON back into YAML
- YAML FormatterFormat and lint the YAML itself
- JSON FormatterMinify or re-indent the JSON output
- JSONPath EvaluatorQuery the converted JSON with a $.path expression
- YAML to PropertiesFlatten application.yml into Spring .properties
- JSON MergeMerge the converted JSON with base settings