DevFormatter

YAML → JSON

 

YAML to JSON Converter

YAML to JSON conversion transforms a YAML document into equivalent JSON by mapping YAML mappings to objects, sequences to arrays, and scalar types to their JSON equivalents. This tool uses js-yaml v5 with the YAML 1.2 Core schema, so only true and false are treated as booleans — not the yes/no/on/off values used in YAML 1.1 environments. All conversion runs in the browser with no data sent to any server.

How YAML to JSON Conversion Works

Last updated: November 2026

YAML (YAML Ain't Markup Language) is a human-readable data serialization language widely used for configuration files in Kubernetes, GitHub Actions, Docker Compose, and Ansible. This converter parses your YAML using js-yaml v5 with the YAML 1.2 Core schema, producing a JavaScript object, then serializes it to formatted JSON using JSON.stringify() with your chosen indentation.

Paste your YAML into the left panel and click Convert to JSON — or just paste and the conversion runs automatically. The JSON output appears in the right panel and can be copied or downloaded.

YAML → JSON Type Mapping

Every YAML construct maps to a JSON equivalent. Understanding the mapping prevents surprises in the output.

YAML construct JSON output Notes
key: value {"key": "value"} Mapping → object
- item ["item"] Sequence → array
42 42 Integer → number
3.14 3.14 Float → number
true / false true / false YAML 1.2 only — yes/no stay as strings
~ or null null Null value
# comment (lost) JSON has no comment syntax
&ref / *ref Expanded inline Full value at each usage point
| or > (multiline) "flattened string" Newlines collapsed or preserved per style

YAML 1.1 vs YAML 1.2 — The Boolean Trap

If your YAML was written for PyYAML, Docker Compose, GitHub Actions, or Ansible, it was likely authored under YAML 1.1 rules. Those parsers treat bare yes, no, on, and off as booleans, and sexagesimal values like 22:30 as the integer 1350.

This converter uses js-yaml v5 (YAML 1.2), which treats those same values as plain strings. The resulting JSON will differ from what the YAML 1.1 system produces. To fix this before converting, use the YAML Formatter's Fix 1.1 Risks button to normalize your YAML first.

Tips & Tricks

Comments don't survive

If your YAML uses comments as inline documentation, extract them to a dedicated _comment key before converting — JSON has no native comment syntax.

Aliases make JSON bigger

An anchor used 10 times expands to 10 full copies in JSON. 20 KB of DRY YAML that uses *ref heavily can easily become 200 KB of JSON.

YAML 1.1 booleans become strings

Bare yes, no, on, off are strings in js-yaml v5. Use the YAML Formatter's Fix 1.1 Risks first if you need them as true booleans.

Dates serialize as ISO strings

2024-01-15 in YAML is parsed as a JavaScript Date and appears as "2024-01-15T00:00:00.000Z" in JSON. Quote the date in YAML to keep it as a plain string.

Large integers lose precision

Numbers above Number.MAX_SAFE_INTEGER (9007199254740991) lose precision in JSON.stringify. Quote them in YAML if they're IDs or other precision-sensitive values.

Multi-document YAML: first doc only

Files with multiple --- separators are only partially converted. Only the content before the second --- is output. Use yaml.loadAll() in code for multi-doc files.

Code Examples

Node.js

import yaml from 'js-yaml';
import fs from 'fs';

const yamlString = fs.readFileSync('config.yaml', 'utf8');
const data = yaml.load(yamlString);           // js-yaml v5, YAML 1.2 Core schema
const json = JSON.stringify(data, null, 2);
fs.writeFileSync('config.json', json);

Python

import yaml
import json

with open('config.yaml') as f:
    data = yaml.safe_load(f)  # PyYAML uses YAML 1.1: yes/no/on/off become True/False

json_str = json.dumps(data, indent=2)
with open('config.json', 'w') as f:
    f.write(json_str)

# For YAML 1.2 behaviour, use ruamel.yaml:
# from ruamel.yaml import YAML
# y = YAML(); data = y.load(open('config.yaml'))

CLI

# Using yq (https://github.com/mikefarah/yq)
yq -o=json config.yaml > config.json

# Using Python one-liner
python3 -c "import yaml,json,sys; print(json.dumps(yaml.safe_load(sys.stdin), indent=2))" < config.yaml

# Using Node.js
node -e "const y=require('js-yaml'),fs=require('fs'); console.log(JSON.stringify(y.load(fs.readFileSync(process.argv[1],'utf8')),null,2))" config.yaml

Frequently Asked Questions

What is YAML to JSON conversion?
YAML to JSON conversion transforms a YAML document into an equivalent JSON representation. YAML mappings become JSON objects, sequences become arrays, and scalar types map to their JSON equivalents. Comments and YAML-specific formatting are lost because JSON supports none of those features. The conversion is performed by a YAML parser such as js-yaml v5, which builds an in-memory JavaScript object from the YAML text, and then JSON.stringify() serializes that object to formatted JSON. The process is lossy in one direction: going YAML to JSON discards comments, anchor/alias markers, and multi-line string styles. Going JSON back to YAML later restores the structure but not the formatting or comments. This tool is commonly used to convert Kubernetes YAML manifests, GitHub Actions workflow files, and Helm chart values into JSON for consumption by REST APIs or JavaScript applications.
What YAML features are preserved in JSON?
All data values are fully preserved: keys, strings, numbers, booleans (true/false), null values, nested objects, and arrays. Anchors and aliases are expanded to their full inline values before serialization, so no data is lost — the output may just be larger. Integer and float values retain their numeric types in JSON. YAML's null (~ or bare null) becomes JSON null. Multi-line block scalars using the literal block style (|) preserve internal newlines as \n in the JSON string, while folded scalars (>) collapse newlines into spaces. Quoted and unquoted YAML strings are both treated as strings — the quoting style is a YAML authoring convention and does not affect the parsed value. Nested structures of any depth are preserved correctly by the recursive parsing process in js-yaml.
What gets lost during YAML to JSON conversion?
Comments are discarded — JSON has no comment syntax. Anchor declarations (&ref) and alias references (*ref) are resolved and expanded inline. Multi-line string styles (literal block | and folded >) are converted to flat JSON strings. The --- document start marker and ... document end marker are YAML syntax elements not represented in JSON, and are silently dropped. YAML's tag directives (%YAML 1.2, !!str, etc.) are processed by the parser to determine type interpretation but do not appear in the JSON output. If your YAML uses inline comments to document key purposes (a common practice in Kubernetes manifests), extract them to dedicated documentation keys before converting if the comments carry semantic meaning your JSON consumer needs.
How are YAML booleans converted to JSON?
This tool uses js-yaml v5 with the YAML 1.2 Core schema, so only the bare values true and false are treated as booleans and produce JSON true/false. The values yes, no, on, off (common in YAML 1.1 files from PyYAML, Docker Compose go-yaml v2, GitHub Actions, and Ansible) are treated as plain strings by this converter. This means a Docker Compose file with tty: yes will produce "tty": "yes" in JSON, not "tty": true. If you need the YAML 1.1 boolean interpretation, use the YAML Formatter's Fix 1.1 Risks feature to normalize the values to true/false before converting, or quote the values in the source YAML to make the string intent explicit.
What is the difference between YAML 1.1 and YAML 1.2 for this converter?
YAML 1.1 parsers — PyYAML, Docker Compose (go-yaml v2), GitHub Actions, and Ansible — coerce bare yes/no/on/off to booleans, sexagesimal values like 22:30 to the integer 1350, and unquoted ISO dates like 2024-01-15 to JavaScript Date objects. YAML 1.2 parsers — js-yaml v5, go-yaml v3, ruamel.yaml in YAML 1.2 mode — do none of that. Only true and false are booleans. If your YAML was written for a 1.1 parser and you convert it here, values like yes will become the string "yes" in JSON rather than true. This is the most common source of unexpected output when converting YAML from infrastructure tools to JSON. The fix is to run Fix 1.1 Risks in the YAML Formatter first.
Does this converter support multi-document YAML?
No. This tool uses js-yaml's load() function, which parses only the first document in a file. Multi-document YAML files (separated by ---) will have only the content before the second separator converted — subsequent documents are silently ignored. For multi-document files in Node.js, use yaml.loadAll(yamlString) which returns an array of parsed objects, then serialize each one separately with JSON.stringify(). Multi-document YAML is common in Kubernetes, where a single .yaml file often bundles a Deployment, Service, and ConfigMap separated by --- markers. The command yq -o=json each-doc.yaml handles this case in a single CLI call by outputting one JSON document per YAML document in the file.
How are YAML anchors and aliases handled?
Anchors (&ref) and aliases (*ref) are fully expanded during parsing by js-yaml before serialization to JSON. The JSON output contains the complete inline data at every alias reference point — there is no JSON equivalent of YAML's anchor/alias mechanism. A heavily DRY YAML file that uses *ref ten times to reference a shared configuration block will produce ten full copies of that block in the JSON output. This is expected and correct — the data is semantically identical, just represented differently. For Kubernetes YAML files that use anchors for common container settings or environment variables, the JSON expansion can be significantly larger. If JSON file size is a concern, consider whether JSON is the right target format or whether the downstream system could accept YAML directly.
Can I convert YAML to JSON in Python?
Yes: import yaml, json; data = yaml.safe_load(yaml_string); json_str = json.dumps(data, indent=2). Note that yaml.safe_load uses YAML 1.1 rules — bare yes/no/on/off become Python True/False, which then serialize to JSON true/false. PyYAML does not implement YAML 1.2 — even yaml.safe_load uses YAML 1.1 boolean rules. For YAML 1.2 behaviour where yes/no remain strings, use ruamel.yaml instead: from ruamel.yaml import YAML; y = YAML(); data = y.load(yaml_string). The ruamel.yaml library is installable via pip install ruamel.yaml and is the correct Python library for YAML 1.2 compliance.
Can I convert YAML to JSON in Node.js?
Yes: import yaml from 'js-yaml'; const data = yaml.load(yamlString); const json = JSON.stringify(data, null, 2). js-yaml v5 uses the YAML 1.2 Core schema by default, so only true and false are treated as booleans. Install via npm install js-yaml. For multi-document YAML, use yaml.loadAll(yamlString) which calls a callback for each document. If you need YAML 1.1 boolean semantics (treating yes/no as booleans), pass the YAML_1_1 schema option: yaml.load(str, { schema: yaml.FAILSAFE_SCHEMA }) or use a custom schema. TypeScript typings are included in the js-yaml v5 package — no need for @types/js-yaml. This tool uses the same js-yaml v5 library, so results will match what you see in the browser.
What is YAML to JSON conversion used for?
YAML to JSON conversion bridges configuration formats and API data formats. Kubernetes manifests, Helm chart values, GitHub Actions workflow files, Ansible playbooks, and Docker Compose files are all authored in YAML because it is more readable and supports comments. However, REST APIs, JavaScript applications, and many data processing tools consume JSON. Converting lets you use YAML's human-friendly syntax during authoring while feeding the data to systems that only accept JSON. Another common use is extracting values from YAML configuration files in CI/CD pipelines: convert to JSON first, then use jq or JSONPath to query specific fields programmatically without a YAML-aware query tool. This is especially useful in GitHub Actions where jq is pre-installed on all runner images and can query JSON natively.
Is my data sent to a server?
No. The conversion runs entirely in your browser using js-yaml v5. Your data never leaves your machine and no account or sign-up is required. The js-yaml library is bundled as a static JavaScript asset and loaded from the same domain as the page. No network requests are made when you click Convert — the entire conversion pipeline runs inside the browser's JavaScript engine. This makes it safe to paste sensitive YAML such as Kubernetes secrets, API credentials, or private configuration files. The tool does not store your input in any database or logging system. Session state is kept only in the browser's localStorage so tabs can be restored, and it is cleared when you close all tabs or clear browser data.
Why is my converted JSON larger than my YAML?
JSON requires quoted string keys and values with commas and brackets, while YAML uses bare keys with indentation. JSON also cannot deduplicate with anchors/aliases — every alias reference is expanded to its full inline value. A YAML file that uses a shared &defaults anchor referenced ten times will produce ten full copies of that block in the JSON output. The ratio is typically 1.5–3x for simple files and can be much higher for anchor-heavy files. Additionally, JSON's mandatory double-quoting of all string values and keys adds bytes that YAML's unquoted syntax avoids. If JSON file size is a concern, minify the output by selecting 0-space indentation, which removes all whitespace from the JSON (not supported in this tool directly, but achievable via JSON.stringify(data) with no indent argument in Node.js).

Related Tools

Other free developer tools available on DevFormatter.