Free tool
YAML to JSON converter
Paste YAML and get formatted JSON as you type. Anchors, aliases and << merge keys are expanded, files with several --- documents become a JSON array, and any error shows the exact line and column.
Free · no sign-up · runs in your browser, nothing is uploaded
Loading the parser…
How YAML becomes JSON
YAML and JSON describe the same kinds of data: maps, lists, strings, numbers, booleans and null. YAML adds features that JSON lacks, and the converter has to turn each one into plain data:
| YAML | JSON | Note |
|---|---|---|
| key: value | {"key": "value"} | A mapping becomes an object, in the same key order. |
| - a | ["a"] | A sequence becomes an array. |
| run: | | "line 1\nline 2\n" | A | block keeps line breaks. A > block folds lines into one, joined by spaces. |
| *anchor | a full copy | Aliases are expanded. JSON has no references. |
| <<: *base | merged keys | Keys from the anchored map are copied in; your own keys win. |
| ~, null, empty | null | An empty value (key:) is also null. |
| --- (several docs) | [ … ] or lines | One array, or JSON Lines with the option above. |
| # comment | (dropped) | JSON has no comments. |
| 1: a | {"1": "a"} | JSON keys are always strings, so non-string keys are converted. |
| .inf, .nan | null | JSON cannot store infinity or NaN. The tool tells you when this happens. |
| !!binary | base64 string | Binary data stays as its base64 text. |
Integers larger than 253 stay exact. Many converters pass them through JavaScript numbers and silently change the last digits of IDs like 12345678901234567890.
YAML 1.1 or 1.2: why the same file can give different JSON
YAML 1.2 (2009) cut down the list of values that turn into booleans and numbers. Many tools still follow YAML 1.1, PyYAML among them. Use the version switch above to see what your parser will produce:
| Unquoted value | YAML 1.2 | YAML 1.1 (PyYAML) |
|---|---|---|
| yes, no, on, off | "yes", "no", "on", "off" | true, false, true, false |
| 22:22 | "22:22" | 1342 (base 60) |
| 0755 | 755 | 493 (octal) |
| 1.10 | 1.1 | 1.1 |
| 2026-10-29 | "2026-10-29" | a timestamp (written as an ISO string here) |
The fix is the same in both versions: quote the value ("22:22", "1.10") when you mean text. The YAML validator flags these values in your file.
Convert YAML to JSON in code
Command line with yq (v4). Add -I=0 for one compact line per document:
yq -o=json '.' config.yaml > config.json yq -o=json -I=0 '.' multi-doc.yaml # one JSON value per line
Python with PyYAML (a YAML 1.1 parser). Use safe_load_all for files with several documents:
import json, yaml
with open("config.yaml", encoding="utf-8") as f:
data = yaml.safe_load(f) # or list(yaml.safe_load_all(f))
print(json.dumps(data, indent=2, default=str)) # default=str handles datesJavaScript / Node.js with the yaml package (YAML 1.2 by default):
import { readFileSync } from 'node:fs';
import { parse, parseAllDocuments } from 'yaml';
const data = parse(readFileSync('config.yaml', 'utf8'));
console.log(JSON.stringify(data, null, 2));
// several documents
const docs = parseAllDocuments(src).map(d => d.toJS());Go with sigs.k8s.io/yaml, the package Kubernetes tooling uses:
import "sigs.k8s.io/yaml" j, err := yaml.YAMLToJSON(yamlBytes)
Things that trip people up
- Duplicate keys. The YAML spec requires unique keys. PyYAML keeps the last value without a word; this tool reports the duplicate so you know which one you lose.
- Custom tags. CloudFormation
!Ref,!Suband!GetAttare not standard YAML. They are converted as plain values and the tag is dropped, with a warning. - Tabs. YAML forbids tabs for indentation. If a file came from an editor that inserts tabs, the validator can replace them in one click.
- Going back. To turn the JSON into YAML again, use the JSON to YAML converter. To check or pretty-print the result, use the JSON formatter.
Working with configs all day? Browse DevOps tools on DevHunt.
More free developer tools
FAQ
How do I convert YAML to JSON?+
Paste the YAML into the box above and the JSON appears on the right as you type. Copy it or download it as converted.json. On the command line, yq -o=json file.yaml does the same, and in Python it is json.dumps(yaml.safe_load(text)).
What happens to YAML comments when converting to JSON?+
They are dropped. JSON has no comment syntax, so no converter can keep them. If you need notes in the JSON, move them into a real field such as "_comment" before converting.
How are YAML anchors and aliases converted?+
An alias (*name) is replaced by a full copy of the value its anchor (&name) points to, and a << merge key copies the anchored map’s keys into the current map, with the keys you write yourself taking priority. JSON has no references, so the result is the expanded data.
What happens to a YAML file with several documents?+
A file with --- separators holds several documents. This converter writes them as one JSON array by default, or as JSON Lines (one compact JSON value per line) if you pick that option. yq instead prints one JSON document after another.
Why did my value turn into true, false or a number?+
YAML guesses types for unquoted values. In YAML 1.1 parsers like PyYAML, yes, no, on and off are booleans, 22:22 is a base-60 number and 0755 is octal. In both versions 1.10 is the number 1.1. Quote the value in YAML to keep it a string. The tool warns about each of these.
Is JSON valid YAML?+
Mostly yes. YAML 1.2 was revised so that JSON is a subset of it, so a YAML 1.2 parser reads ordinary JSON files. That is also why converting YAML to JSON and back keeps the data the same, apart from comments, anchors and formatting.
Is my YAML uploaded anywhere?+
No. The conversion runs in your browser with the open source yaml library. Nothing is sent to a server, so it is safe for configs that contain internal hostnames. Small inputs are kept in the page URL so you can share a result; do not share links that contain secrets.
Sources: YAML 1.2.2 specification · YAML 1.1 boolean type · YAML 1.1 merge key · RFC 8259 (JSON) · yq: convert JSON and YAML · yaml library docs · PyYAML resolver. Checked October 2026.