About the YAML to JSON Converter
This YAML to JSON converter translates YAML — the format used by Kubernetes manifests, Docker Compose files, GitHub Actions workflows, OpenAPI specs and countless app configs — into formatted JSON, and converts JSON back into readable YAML. It doubles as a YAML validator: if the input is malformed, it tells you what is wrong and on which line.
It handles the YAML you meet in practice: nested mappings and sequences, lists of objects, inline [flow] and {flow} collections, single- and double-quoted strings, literal (|) and folded (>) multi-line blocks, comments, anchors and aliases (&default / *default) and merge keys (<<). Only the first document of a multi-document file is converted.
Values are typed using the YAML 1.2 core schema: true/false, null or ~, integers and floats become JSON booleans, null and numbers, and everything else stays a string. Unlike older YAML 1.1 parsers, yes/no and on/off stay strings — quote values like "08080" or "no" when you want them treated as text in every tool.
How to use the yaml to json converter
- 1Choose YAML → JSON or JSON → YAML.
- 2Paste your YAML file or JSON document into the input.
- 3Pick JSON indentation (2 or 4 spaces, or minified).
- 4Check the validation message — errors include the line number.
- 5Copy the converted output.
Formula and method
YAML → JSON: the parser reads the text line by line. Indentation defines structure — "key: value" lines at the same indent form a mapping (JSON object), "- item" lines form a sequence (JSON array), and a deeper-indented block after "key:" becomes that key’s value. Inline [a, b] and {a: 1} collections, quoted strings with escapes, | literal and > folded blocks (with -, + chomping), comments, anchors, aliases and << merge keys are resolved, then plain values are typed with the YAML 1.2 core schema and the result is printed with JSON.stringify.
JSON → YAML: objects become indented "key: value" blocks, arrays become "- " lists, multi-line strings become | blocks, and strings that would otherwise be misread (numbers, true/false, yes/no, leading symbols, ": " or " #") are double-quoted.
Worked examples
Service config with lists, flow sequence and block text
Nested keys become nested objects, the [db-1, db-2] flow list and the "- name:" items become arrays, 8080 and 0.25 become numbers, and 2.4.1 stays a string because it is not a valid number. The | block keeps its line breaks plus one trailing newline, and ~ becomes null.
JSON to YAML
Objects become indented keys and arrays become "- " lists. The string "false" is quoted so a YAML parser does not read it as a boolean, while v1.2 is safe unquoted; the empty object is written inline as {}.
Anchors, merge keys and folded text
prod merges the anchored defaults but overrides timeout with 60. The folded (>) block joins its lines with a space and keeps one final newline. Minified output removes all whitespace.
Validation error
The flow sequence is never closed with "]", so the input is reported as invalid YAML instead of producing wrong JSON.
Frequently asked questions
How do I convert YAML to JSON?+
Paste the YAML into the input with the direction set to YAML → JSON. Mappings become JSON objects, lists become arrays, and numbers, booleans and null are typed automatically. Copy the formatted JSON from the output box.
Is every JSON file valid YAML?+
Practically yes — YAML 1.2 was designed as a superset of JSON, so a JSON document can be read by a YAML 1.2 parser. The reverse is not true: YAML features like comments, anchors and block scalars have no JSON equivalent.
Why did "no" or "on" stay a string?+
This converter follows the YAML 1.2 core schema, where only true and false are booleans. Older YAML 1.1 parsers (such as PyYAML) also treat yes, no, on and off as booleans — the famous "Norway problem" — so quote such values to be safe everywhere.
What happens to YAML comments?+
Comments are ignored during conversion because JSON has no comment syntax. If you need to keep them, store the information in a field such as "description" or keep the YAML file as the source of truth.
Why is my YAML invalid?+
The most common causes are tab characters used for indentation (YAML only allows spaces), inconsistent indentation between sibling keys, a missing space after the colon in "key:value", and unclosed quotes or brackets. The error message shows the line to check.