YAML to JSON
Free online YAML to JSON converter powered by the js-yaml library. YAML mappings and sequences convert to JSON objects and arrays; pretty mode toggleable; built-in tryFixYAML auto-repairs 5 common errors (tabs, unclosed quotes, indentation, key format, trailing spaces). 100% in your browser.
Related
About YAML to JSON: convert YAML config to standard JSON objects automatically
YAML to JSON is the process of converting YAML (YAML Ain't Markup Language) format configs to JSON objects. YAML is a human-friendly data serialization format, widely used in Kubernetes (k8s manifests, Helm charts), Docker Compose, Ansible playbooks, GitHub Actions, Prometheus configs, and other modern DevOps and cloud-native scenarios. JSON is the standard format for Web APIs, the JavaScript ecosystem, and config files. Each format has its strengths: YAML is concise, readable, supports comments and complex structures, and suits human editing; JSON is explicit, easy for machines to parse, and suits API transmission. This tool is designed to automatically convert YAML configs to JSON for modern applications.
The tool's core is using the js-yaml library to parse the YAML structure, then serializing to a JSON object via JSON.stringify. js-yaml is a mature JavaScript YAML parser supporting all standard YAML 1.1 syntax: scalars (string, number, boolean, null, date), sequences (array), mappings (object), anchors (&), aliases (*), multiline strings (| or >), comments (#). Using a mature library brings the advantages of high stability, fewer bugs, and full YAML spec support.
The YAML-to-JSON mapping rules are intuitive: YAML mappings (key: value) become JSON objects ({"key": "value"}); YAML sequences (- item) become JSON arrays (["item"]); YAML nested structures become corresponding JSON nested objects and arrays; YAML strings/numbers/booleans/null types keep their corresponding types in JSON. YAML comments (#) are auto-ignored because the JSON standard doesn't support comments.
The pretty output mode (default 2-space indent) generates JSON that's highly readable for human review, copying, and version comparison; the non-pretty mode outputs compact single-line JSON suitable for network transmission, API responses, and database storage. Toggle between modes via the Format output checkbox in the bottom toolbar.
Error self-repair (tryFixYAML) is the tool's practical design. Real-world YAML files often have 5 categories of issues: 1) mixed tabs and spaces (YAML requires consistent spaces); 2) trailing whitespace; 3) unclosed quotes (odd number of single or double quotes); 4) indentation not a multiple of 2 (YAML requires consistent incremental indentation); 5) keys with hyphens or spaces requiring quoting. The tool auto-detects and fixes these issues, and tells the user what was fixed.
YAML anchors and aliases are advanced YAML features. &anchor defines a tag that can be referenced; *alias references the tag elsewhere. js-yaml first parses to a JavaScript object (with references replaced by actual content), so the final generated JSON doesn't contain anchor information, and the same object content appears multiple times in the JSON. This conforms to the JSON data model (JSON is a value-type language with no reference concept), but means developers will have redundant storage of repeated content.
YAML 1.1 vs 1.2 differences. YAML 1.1 is the widely deployed version (js-yaml default), including octal numbers (0123), sex single-character (yes/no/true/false), Norway abbreviation (foo: !!str bar), etc. YAML 1.2 is the latest stable version, removing these ambiguous features, more consistent with the JSON spec. The tool defaults to YAML 1.1 for maximum compatibility; for YAML 1.2 strict mode, use schema: CORE_SCHEMA.
Real-time conversion is a practical feature. After typing stops, the tool converts with 400ms debounce; developers can quickly iterate, modify, and see effects. Combined with shortcuts and the sample button, developers can quickly complete the full workflow from YAML config to JSON conversion.
Pure client-side processing is the tool's core architecture. All YAML parsing, JSON serialization, and error repair happen in browser JavaScript; js-yaml is the only external dependency (~50KB) loaded via npm. Original YAML data (which may contain sensitive configs like k8s secrets, API keys, database credentials) is not sent to a server, so sensitive configs can be safely processed locally.
Use Cases
- Convert Kubernetes manifests, Helm chart values.yaml and other K8s config files to JSON for kubectl apply --validate or jq queries, merges, and CI/CD pipelines.
- Convert Docker Compose files (docker-compose.yml) to JSON for docker stack deploy to Swarm clusters, or import to other container orchestration tools.
- Convert GitHub Actions, GitLab CI, CircleCI pipelines (.github/workflows/*.yml) to JSON for version comparison and templating.
- Convert Ansible playbooks (playbook.yml, hosts, roles) to JSON for programmatic processing with Python or Node.js config loaders.
- Convert Prometheus alert rules, Alertmanager config, Promtail/Grafana Loki config to JSON for dynamic generation and testing.
- Convert ESLint, Prettier, Stylelint, Commitlint frontend tool config (.eslintrc, .prettierrc) to JSON for IDE plugins and editors.
- Convert swagger/openapi YAML spec files to JSON, with swagger-codegen or openapi-generator to generate client SDKs or server stub code.
- Teach the conversion relationship between YAML and JSON, comparing syntax differences, indentation rules, comment handling, and type mapping.
How to Use
- Paste your YAML into the left editor, click Upload to select a .yaml/.yml/.txt file, or click Sample to load the built-in user config example.
- The tool converts automatically 400ms after typing stops. View the converted JSON on the right with CodeMirror syntax highlighting.
- Click the Format output checkbox in the bottom toolbar to toggle between pretty (2-space indent) and compact output modes in real time.
- If YAML has syntax errors, click the Fix structure button next to the error message. The tool calls tryFixYAML to auto-fix 5 common errors and prompts which lines were corrected.
- Click Copy to put the JSON on the clipboard, or click Download to save as converted.json file (MIME: application/json).
- Paste the JSON into your target code (kubectl apply, swagger-codegen, custom Node.js config loader, etc.) or import into your backend service for further processing.
Features
- js-yaml library parsing: powered by the mature js-yaml library supporting all standard YAML 1.1 syntax (scalars, sequences, mappings, anchors, aliases, multiline strings, etc.), no dependencies.
- Smart error repair: built-in tryFixYAML automatically fixes 5 common YAML errors (tabs, unclosed quotes, irregular indentation, special-character keys, trailing whitespace).
- Pretty output mode: default 2-space indentation for readable output; non-pretty mode outputs compact single-line JSON for network transmission.
- Complete type support: supports all YAML scalar types (string, number, boolean, null, date), sequences (array), mappings (object) in both directions.
- Recursive nested structures: any-depth YAML nested mappings and sequences recursively convert to corresponding JSON nested objects and arrays.
- Anchor and alias resolution: supports YAML anchors (&anchor) and aliases (*alias), js-yaml automatically resolves reference relations, JSON shows the expanded content.
- YAML comment ignored: YAML comments (#) are automatically ignored, the converted JSON is pure data, no comments.
- Real-time auto conversion: 400ms debounce after typing stops, combined with keyboard shortcuts for efficiency.
- JSON syntax highlighting: right side uses CodeMirror JSON syntax highlighting for easy reading of complex JSON structures.
- 100% browser-side: all YAML parsing, JSON serialization, and error repair happen in client-side JavaScript; original config is not uploaded.
- History recovery: automatically saves the last 200 history items, and restores the previous input on page load.
- Complete shortcut system: convert, upload, copy, download, clear common operations, following mainstream JSON/YAML editor conventions.
FAQ
How do I convert YAML to JSON format?
Paste your YAML into the left editor and the tool uses the js-yaml library to parse the YAML structure (mappings, sequences, comments, etc.) and convert it to a standard JSON object. Mapping: YAML maps become JSON objects ({key: value}), YAML sequences become JSON arrays ([item1, item2]), and YAML strings/numbers/booleans map directly to corresponding JSON types. Conversion runs automatically 400ms after typing stops.
Are YAML comments (#) preserved in JSON?
No. YAML comments (lines starting with #) are only for developer readability; js-yaml automatically ignores them during parsing. The converted JSON is pure data with no comments. To preserve documentation, keep the original YAML file as the comment source, or use a 'comment' field explicitly in JSON.
Which YAML data types are supported?
All standard YAML 1.2 types are supported: scalars (string, number, boolean, null), sequences (lists/arrays), mappings (objects/dictionaries), nested structures, multiline strings (| or >), anchors and aliases (& and *), document separators (---). Special formats like dates and ISO 8601 timestamps are auto-parsed as JavaScript Date objects (then serialized to JSON strings).
What is pretty output mode?
The tool supports two output modes: pretty (default) outputs JSON with 2-space indentation and line breaks for high readability and easy manual editing; non-pretty outputs compact single-line JSON suitable for network transmission, API responses, and database storage. Toggle via the 'Format output' checkbox in the bottom toolbar.
Can the tool handle improperly formatted YAML (e.g. wrong indentation)?
Yes. The built-in tryFixYAML repair function automatically fixes 5 common errors: 1) tabs converted to 2-space indentation; 2) trailing whitespace removed; 3) unclosed single/double quotes closed; 4) non-2x indentation corrected; 5) keys with hyphens or spaces auto-quoted. This significantly improves compatibility with real-world imperfect YAML.
Which input file types are supported?
Supports .yaml, .yml, and .txt files (UTF-8 encoded). Click the Upload button to select a local file; the tool reads it via the browser's native FileReader API without uploading to a server. After upload, content is automatically filled into the input box and triggers conversion. File type validation happens on the client.
What can I open the downloaded JSON file with?
The downloaded converted.json is a UTF-8 encoded standard JSON file (MIME: application/json). You can open it with any text editor (VS Code, Sublime, Notepad++) or specialized JSON tool (jq, JSDoc), or drag it into a browser to view the formatted structure. Almost all programming languages have built-in JSON parsers.
Are YAML multiline strings supported?
Yes. YAML provides two multiline string syntaxes: literal block (|) preserves line breaks, folded block (>) folds line breaks into single spaces. js-yaml parses both correctly. Multiline strings appear in JSON as strings with the appropriate line breaks or single spaces.
How are YAML anchors and aliases converted?
YAML supports anchors (&anchor) and aliases (*alias) for referencing repeated content. js-yaml first parses to a JavaScript object, where anchors and aliases are internally resolved (each alias reference is replaced with the actual anchor content). So the final generated JSON does not contain anchor information, and the same object content will appear multiple times in the JSON (not sharing references). This conforms to the JSON data model (no reference concept).
How are dates and times in YAML handled?
js-yaml follows the YAML 1.1/1.2 specification: ISO 8601 format dates/timestamps (such as 2026-01-15T10:30:00Z) are automatically parsed as JavaScript Date objects. When converted to JSON, Date objects are serialized as ISO 8601 strings via JSON.stringify. Note that the type is lost (JSON has no native Date type); you may need type annotations in the application layer.
Which YAML versions are supported?
The tool supports YAML 1.1 (default) and YAML 1.2 (via schema options) through js-yaml. YAML 1.2 is the latest stable version, removing some ambiguous syntax from 1.1 (such as octal numbers, single-character sex values), and is recommended. The tool defaults to YAML 1.1 for maximum compatibility. To enable YAML 1.2 strict mode, use schema: CORE_SCHEMA or JSON_SCHEMA.
What input file size is supported?
There is no hard limit; the practical limit is browser memory. YAML up to 1-2 MB works smoothly; larger files may slow down because of js-yaml's memory footprint. For processing large Kubernetes manifests or Docker Compose files, consider trimming or splitting them in a local YAML editor. All parsing happens locally in the browser, so sensitive configurations (like k8s secrets) are not sent to a server.
Troubleshooting
YAML parse error 'unexpected token' - what to do?
The cause is usually indentation errors (mixing tabs and spaces, inconsistent levels), unclosed quotes, missing colons in key-value pairs, or misplaced list dashes. Click the Fix structure button next to the error message; the tool calls tryFixYAML to auto-fix 5 common errors and prompts which lines were corrected. If it still cannot parse, check that the YAML doesn't use non-standard syntax (like tab indentation).
YAML anchor reference (*alias) is lost after conversion?
This is normal behavior. js-yaml auto-expands references during internal parsing, so the final JSON doesn't retain anchor information, and the same object content appears multiple times in the JSON (not sharing references). To preserve reference relations, use $ref fields in the parsed JSON (JSON Reference spec) or maintain reference maps in the application layer.
Boolean values became strings?
In YAML 1.1, yes/no/on/off/true/false are all parsed as booleans (YAML 1.2 removed yes/no). If your YAML 1.2 file uses yes/no but is parsed as a string, change them to true/false, or add quotes 'yes' before parsing to force string type.
Why did dates become ISO strings?
ISO 8601 dates in YAML (such as 2026-01-15, 2026-01-15T10:30:00Z) are auto-parsed as JavaScript Date objects by js-yaml. JSON.stringify serializes Date objects using toISOString() to output ISO strings. If you need to preserve a custom format (such as YYYY-MM-DD HH:mm:ss), you can use date-fns, moment.js, or similar libraries to reformat after parsing.
How to preserve YAML comments?
The tool does not currently preserve comments, because the JSON standard does not support comments. Suggested approaches: 1) Maintain comments in the original YAML file (comments are for developer communication); 2) Use a 'comment' field in JSON to explicitly store documentation; 3) Use dedicated documentation tools (such as Swagger's openapi spec) to preserve API documentation.
How are multi-document YAML files (separated by ---) handled?
Only the first YAML document is parsed by default. js-yaml supports the loadAll() method for multi-document parsing, but the tool currently only supports single documents. For handling multi-document YAML, split into multiple files using a text editor first, or use js-yaml's loadAll() API for custom implementation.
What can I open the downloaded .json file with?
The downloaded converted.json is a UTF-8 encoded standard JSON file (MIME: application/json). You can open it with any text editor (VS Code, Sublime, Notepad++) or specialized JSON tool (jq, JSDoc), or drag it into a browser to view the formatted structure. Almost all programming languages have built-in JSON parsers.
Glossary
- YAML (YAML Ain't Markup Language)
- Human-friendly data serialization format designed in 2001 by Clark Evans et al. Uses indentation for hierarchy, supports comments, lists, mappings, multiline strings, anchors and aliases. It's the de facto configuration standard for Kubernetes, Docker Compose, Ansible, GitHub Actions, and other modern DevOps tools.
- JSON (JavaScript Object Notation)
- Lightweight data-interchange format based on JavaScript object syntax but independent of any programming language. Supports six basic types: object ({}), array ([]), string, number, boolean, and null. It's the de facto standard for modern Web APIs, NoSQL databases, and the JavaScript ecosystem.
- js-yaml
- Mature JavaScript YAML parser and serializer (~50KB) supporting the full YAML 1.1 spec and parts of 1.2. The tool uses this library to parse YAML into JavaScript objects, then serializes to JSON via JSON.stringify.
- Indentation
- YAML strictly uses indentation to express hierarchy. Must use spaces (not tabs) and the indentation must be consistent (such as 2 spaces). This is one of the most common sources of YAML errors. The tool auto-detects and fixes indentation issues.
- Anchors and aliases (& *)
- Advanced YAML features. &anchor defines a tag that can be referenced; *alias references the tag. js-yaml automatically expands references during internal parsing, so the final JSON doesn't retain these tags, only the expanded data.
- Multiline strings
- YAML provides two multiline string syntaxes. Literal block (|) preserves newlines; folded block (>) folds multiple newlines into single spaces. js-yaml correctly parses both syntaxes, and converts to JSON while preserving or folding newlines per spec.
- Document separator (---)
- Three consecutive hyphens (---) in YAML denote document separators, often used to include multiple YAML documents in one file. js-yaml by default only parses the first document; multi-document parsing requires special handling.
- YAML 1.1 vs 1.2
- YAML 1.1 (2005) is widely deployed, supporting octal, sex single-character, Norway abbreviation, etc. YAML 1.2 (2009) removed ambiguous features, more compatible with JSON. The tool defaults to YAML 1.1 for maximum compatibility.
- Anchor (&)
- In YAML, &name defines a tag that can be referenced by *name later, often used to avoid repeating the same config block across multiple documents.
- Alias (*)
- In YAML, *name references a tag previously defined with &name; js-yaml replaces the reference with actual content during parsing, so the final JSON contains no alias information.
- JSON.stringify
- JavaScript built-in method to serialize an object to a JSON string. The tool uses the 2nd parameter (replacer) and 3rd parameter (space) to control indentation: space=2 generates pretty output, space=undefined outputs compact single-line.
- tryFixYAML
- The tool's built-in YAML repair function that auto-detects and fixes 5 common errors: tabs to spaces, remove trailing whitespace, close unclosed quotes, fix non-2x indentation, add quotes to keys with special characters. Handles non-standard YAML in real projects.
- Pretty output
- The tool's toggleable output mode. When enabled, outputs JSON with 2-space indentation and line breaks (good for human review); when disabled, outputs compact single-line JSON (good for API transmission, storage).
YAML to JSON type mapping rules
The tool's YAML-to-JSON conversion mapping rules based on js-yaml:
| YAML type | YAML example | JSON output | Mapping rule |
|---|---|---|---|
string | name: Alice | "name": "Alice" | YAML string values become JSON strings (with double quotes) |
number | age: 30 | "age": 30 | YAML numbers stay as JSON numbers (no quotes) |
boolean | isActive: true | "isActive": true | YAML booleans (true/false) stay as JSON booleans |
null | value: null / value: | "value": null | YAML null or empty becomes JSON null |
sequence | - a\n- b\n- c | ["a", "b", "c"] | YAML lists (-) become JSON arrays |
mapping | name: Alice\nage: 30 | {"name": "Alice", "age": 30} | YAML mappings (key: value) become JSON objects |
nested mapping | user:\n name: Alice\n age: 30 | {"user": {"name": "Alice", "age": 30}} | YAML nested indentation becomes JSON nested objects |
list of objects | - name: a\n- name: b | [{"name": "a"}, {"name": "b"}] | YAML list items as objects become JSON object array |
date | createdAt: 2026-01-15 | "createdAt": "2026-01-15T00:00:00.000Z" | ISO 8601 dates become Date objects then serialized to ISO string |
YAML vs JSON format comparison
A comparison of the two formats across different dimensions, helping understand when to choose YAML or JSON:
| Dimension | YAML | JSON | Notes |
|---|---|---|---|
| Syntax | indent + : - concise | { } : [ ] strict | YAML concise but error-prone (indentation-sensitive), JSON strict but verbose |
| Comments | # comments | not supported | YAML supports comments, JSON standard does not |
| Data types | scalars, sequences, mappings | string, number, boolean, null, object, array | YAML richer (includes date, binary, etc.), JSON simpler |
| Arrays | - item1\n- item2 | ["item1", "item2"] | YAML uses dashes, JSON uses brackets |
| Readability | high (no quotes/brackets) | medium (bracket noise) | YAML more human-friendly |
| Multiline strings | | or > block syntax | needs \n escaping | YAML native support, JSON needs escaping |
| References | &anchor *alias | not supported (must repeat) | YAML supports anchor-alias, JSON must repeat |
| Use cases | config files, CI/CD, k8s | API response, storage, Web | YAML suits config, JSON suits API |
Common YAML errors and fixes
The 5 common YAML errors the tool's tryFixYAML auto-detects and fixes:
| Error type | Error example | Auto-fix | Notes |
|---|---|---|---|
| Tab indentation | key:\n\tvalue | key:\n value | |
| Trailing whitespace | key: value | key: value | |
| Unclosed quotes | key: 'value | key: 'value' | |
| Irregular indentation | key:\n value | key:\n value | |
| Key with special chars | my-key: value | "my-key": value |
Privacy & Security
This YAML to JSON tool runs entirely in your browser. YAML parsing (powered by the mature js-yaml library), JSON serialization, and error repair (tryFixYAML) all happen in client-side JavaScript; js-yaml is the only external dependency (an ~50KB npm package). Original YAML data (which may contain sensitive configs like k8s secrets, API keys, database credentials) is never sent to a server. File uploads use the browser's native FileReader API and never go through an intermediate service. The tool uses no tracking cookies and collects no input or usage data. All input and output are cleared from memory as soon as the page is closed or refreshed. Safe to use for YAML files containing sensitive configurations (k8s secrets, API keys, database credentials, enterprise DevOps pipelines).
Authoritative References
- YAML.orgYAML 1.2 Specification
- GitHubjs-yaml GitHub Repository
- KubernetesKubernetes YAML Reference
- DockerDocker Compose Specification
- AnsibleAnsible YAML Guide
- GitHubGitHub Actions YAML Documentation
- JSON Compress
- CSV to JSON
- JSON to CSV
- JSON Diff
- JSON Escape / Unescape
- JSON Flatten
- JSON Formatter
- JSON Generator
- JSONPath Query
- JSON Merge
- JSON Repair
- JSON Schema Validator
- JSON Sort
- JSON Stringify
- JSON to HTML Table
- JSON to Java
- JSON to Markdown
- JSON to SQL
- JSON to TOML
- JSON to TypeScript
- XML to JSON
- JSON to XML
- YAML to JSON
- JSON to YAML
- JSON to Python
- JSON to Go
- JSON to Rust
- JSON to Swift
- JSON to C#
- JSON to C++
- JSON to PHP