JSON to YAML
Free online JSON to YAML converter. Instantly transform JSON into standard YAML 1.2 configuration. Supports custom indentation and intelligent repair of JSON syntax errors. Generate YAML config files for Kubernetes resources, Docker Compose, GitHub Actions, and more.
Related
What is YAML? Why convert JSON to YAML?
YAML (YAML Ain't Markup Language) is a human-friendly data serialization format designed to make config files easy to read and write. YAML 1.2 is the current stable version (yaml.org/spec/1.2.2), originally proposed by Clark Evans in 2001. It is now widely used for configuration across nearly every major DevOps tool, including Kubernetes, Docker Compose, GitHub Actions, Ansible, CircleCI, and Prometheus. YAML's design philosophy emphasizes readability over compactness, sacrificing JSON's machine-friendly terse syntax in favor of an indentation-and-comment structure that's friendly for human editing.
JSON and YAML are supersets of each other (JSON is a subset of YAML), so converting from JSON to YAML is technically a simple syntactic reformatting — but the practical benefits are significant: ① Improved readability — YAML uses indentation instead of curly braces and commas, and quotes around keys can often be omitted, which dramatically improves readability; ② Comment support — YAML supports # comments, whereas the JSON standard does not (although many tools support #!shebang or lenient parsing); ③ Multi-document support — YAML uses the --- separator to support multiple documents in a single file (multi-document); a single Kubernetes YAML file can contain Deployment + Service + ConfigMap; ④ Automatic type recognition — YAML identifies numbers, booleans, and null without quotes, keeping config files cleaner.
YAML has three basic data structures: ① scalar — a single value like a string, number, boolean, or null; ② sequence — similar to a JSON array, denoted by a leading -; ③ mapping — similar to a JSON object, denoted by key: value. YAML also has several advanced structures: anchors (&anchor) and references (*anchor) allow reusing config blocks; block scalars (| preserves line breaks) and folded scalars (> turns line breaks into spaces) control multi-line string output; explicit tags (!!str, !!int) can force types. These features make YAML more powerful than JSON in complex configuration scenarios.
Common motivations for converting JSON to YAML include: ① A project needs to deploy to Kubernetes but the existing config is in JSON format; ② The team has decided to use YAML to manage all configuration files uniformly; ③ Integration with third-party APIs requires YAML-format request bodies (OpenAPI, Swagger); ④ JSON configs exported from API gateways or CI/CD platforms need to become human-readable YAML; ⑤ Converting mock data from JSON to YAML makes it easier to write test fixtures. This tool covers all of these scenarios.
The conversion process is essentially a data-structure remapping: JSON.parse() parses the text into a JavaScript object (AST), then the js-yaml dump() function recursively walks every node — strings, numbers, booleans, and null are output directly, arrays become - lists, and nested objects become indentation levels. The entire process runs purely locally with no external dependencies (besides the js-yaml library itself), and the output is 100% compatible with every standard YAML parser.
Use Cases
- Kubernetes manifest preparation: Convert JSON configs from Helm templates or CI/CD tooling into standard Deployment/Service YAML.
- Docker Compose configuration: Convert JSON exported from docker-compose.json tools or container platforms into readable docker-compose.yml.
- GitHub Actions / GitLab CI workflows: Convert JSON configs from automation scripts or template tools into YAML pipeline files.
- Ansible Playbook authoring: Convert task orchestration JSON into the YAML format Ansible expects, making team code reviews easier.
- Unified microservice config: Migrate JSON configs scattered across microservices into a YAML repository for versioning and auditing.
- Generate YAML from Swagger/OpenAPI: Convert API tool-exported JSON Schema into OpenAPI-standard YAML specifications.
- Learning YAML syntax: Use an existing JSON structure to intuitively see how YAML expresses nested objects, arrays, and special values.
- Config format comparison & conversion: Quickly switch between JSON and YAML to compare formats and pick the best fit for your project.
How to Use
- Paste JSON content into the left editor, or click the upload button to choose a .json / .txt file. You can also click "Example" to load a preset sample.
- The tool automatically converts in real time following the YAML 1.2 specification, with the result shown instantly on the right. Use the dropdown menu to switch between 2-space and 4-space indentation.
- If your JSON has syntax errors (such as trailing commas, single quotes, or comments), a "Repair JSON" button will appear at the bottom — click it to auto-fix in one step.
- When Unicode escaping or string escaping is needed, use the "Chinese ↔ Unicode" or "Escape / Unescape" buttons in the bottom toolbar to convert in one click.
- Once satisfied with the result, click "Copy" to copy the YAML content, or click "Download" to save it as output.yaml for your project.
Features
- Standard YAML 1.2 output: Strictly follows the official YAML 1.2 specification. Ready to use directly with Kubernetes, Docker Compose, GitHub Actions, Ansible, and other mainstream tools.
- Customizable indentation: Switch freely between 2-space and 4-space indentation to match your project's code style (YAML officially recommends 2 spaces).
- Smart JSON repair: Built-in tryFixJSON engine. Automatically detects and fixes trailing commas, single quotes, comments, and other common JSON errors before conversion.
- Bidirectional Unicode conversion: One-click conversion of Chinese characters to \uXXXX Unicode escape sequences, or convert Unicode back to Chinese — perfect for internationalization scenarios.
- String escape / unescape: One-click escape of double quotes, backslashes, and newlines in JSON, or restore escaped strings back to their original form.
- JSON format & minify: The left input area supports formatting JSON into a beautified indented version or minifying it into a single-line compact version.
- Real-time bidirectional editing: Paste JSON on the left and instantly see the YAML result on the right. Conversion happens as you type — no button clicks required.
- File upload & download: Upload .json / .txt files, then download the result as config.yaml or output.yaml with one click.
- Keyboard shortcuts: Shift+Cmd/Ctrl+F to format, C to minify, U for Unicode, Z to reverse, / to escape, . to unescape, O to upload, D to download, K to clear.
- Resizable panels & history: Drag the divider on desktop to resize the left/right panels. The tool automatically saves the most recent 200 entries for easy recall.
- Jump to JSON formatter: After conversion, jump straight to the JSON formatter tool to beautify, validate, or minify the source data.
- Pure front-end local processing: All parsing, conversion, and escaping happens in browser JavaScript. Sensitive configurations are never uploaded to any server.
FAQ
How do I convert JSON to YAML format?
Paste your JSON into the left editor and the tool will automatically convert it into a human-readable format following the YAML 1.2 specification: key-value pairs become key: value, nested objects are represented by indentation, and arrays become the `- item` list syntax. Once converted, you can copy the result or download it as a .yaml file. If the JSON has syntax errors (such as trailing commas, single quotes, or comments), the tool will automatically attempt to repair them before conversion.
Which scenarios are JSON and YAML each best suited for?
YAML is better suited for human-readable configuration scenarios — Kubernetes resource manifests, Docker Compose, GitHub Actions, Ansible Playbooks, CI/CD pipeline configs. JSON is better for machine parsing and data exchange — REST API request/response payloads, microservice communication, frontend/backend data transfer. A simple rule: choose YAML for writing configs, choose JSON for transmitting data. This tool also supports the reverse direction: YAML to JSON.
Should JSON-to-YAML use 2-space or 4-space indentation?
The YAML specification officially recommends 2-space indentation (consistent with Python style), which is the default in mainstream tools like Kubernetes, Docker Compose, and GitHub Actions. However, some projects (e.g., certain legacy Ansible projects or Google's internal style) use 4 spaces. This tool supports free switching between 2 and 4 spaces — simply use the dropdown menu in the top-right of the output area to change indentation instantly without reconverting.
Can the generated YAML be used directly with Kubernetes?
Yes. This tool strictly follows the official YAML 1.2 specification, so the output meets the syntax requirements of the Kubernetes YAML parser (kubectl apply). The generated YAML can be saved directly as deployment.yaml, service.yaml, etc., and applied with kubectl apply -f. Note: YAML is very sensitive to indentation — don't introduce extra spaces or use Tab characters when copying.
Does it support generating multi-document YAML (separated by ---)?
The current version primarily focuses on single-document JSON → YAML conversion. If your JSON is an array of independent objects, the conversion output will be in list form. If you need multi-document YAML (with --- before each object), you'll need to manually add the --- separator before each object after conversion, or use our YAML formatter tool for further processing.
Will Chinese or special characters in JSON become garbled?
No. This tool fully supports UTF-8 encoding, including all Unicode characters such as Chinese, Japanese, Korean, emoji, and special symbols. If you need to convert Chinese characters to \uXXXX escape sequences (for example, to embed them in a JavaScript string literal), use the "Chinese → Unicode" button at the bottom of the tool. Use "Unicode → Chinese" for the reverse conversion.
How are double quotes and newlines in JSON strings handled?
YAML supports multiple string styles: ① plain (no quotes — for simple strings without special characters); ② double-quoted (supports \n, \t, and other escapes); ③ single-quoted (literal, no escaping); ④ | block scalar (preserves line breaks); ⑤ > folded scalar (line breaks become spaces). The tool outputs double-quoted strings by default. If your JSON strings contain line breaks, YAML will automatically escape them as \n. The "Escape / Unescape" buttons at the bottom handle special scenarios.
Did all values become strings after converting JSON to YAML?
By default, the tool intelligently recognizes and preserves the original JSON types: numbers stay as YAML numbers (no quotes), booleans become true / false, and null becomes null or ~. However, if you need all values to be strings (some config systems strictly require strings), you can add quotes manually after conversion, or wrap all values as strings in your JSON before converting.
Since it runs locally in the browser, will my config files be uploaded?
No. All JSON parsing, YAML generation, string escaping, Unicode conversion, and JSON repair happen entirely in your browser's local JavaScript engine. Nothing is sent over the network to any server, and the tool works fully offline. You can safely convert JSON containing database passwords, API keys, or Kubernetes Secret configurations.
Troubleshooting
JSON error "Unexpected token" — what do I do?
This is a JSON syntax error. Common causes: ① Extra trailing commas, e.g. {"a":1,}; ② Single quotes instead of double quotes, e.g. {'a':1}; ③ Key names without double quotes, e.g. {a:1}; ④ Comments using // or /* */. The "Repair JSON" button at the bottom of the tool will automatically attempt to fix trailing commas, add missing double quotes, and strip comments. Re-convert after repair.
kubectl apply fails with "yaml: invalid character"?
This is usually an indentation error. YAML strictly requires space indentation — mixing in Tab characters will cause parsing to fail. Check: ① All indentation uses spaces (not Tabs); ② The number of spaces is consistent at the same level (2 or 4 spaces); ③ Indentation aligns with the intended nesting levels. This tool outputs pure-space indentation and never mixes in Tabs, but pasting manually may introduce Tab characters.
Newlines in YAML strings became \n — how do I fix that?
By default, line breaks (\n) inside JSON strings are escaped as \n when converted to YAML. To preserve actual line breaks (e.g., a multi-line command in Docker Compose, or a multi-line config value), you need to manually switch to YAML's block scalar style after conversion: use the | symbol, for example description: | first line second line. Alternatively, use the tool's "Unescape" button to convert \n back to real newlines before conversion.
Null values became ~ symbols in the converted YAML?
YAML uses ~ or null to represent empty values — the two are equivalent. If your tooling doesn't recognize ~, you can manually replace it with null. Alternatively, switch the output option in the tool so that all null values are explicitly output as null instead of ~. Also note that in YAML 1.1, NO / On / Off are parsed as the boolean false (the Norway Problem); YAML 1.2 fixed this, and this tool's output complies with the 1.2 specification.
Chinese shows up as \uXXXX escapes in the YAML?
By default, the tool outputs native UTF-8 Chinese (no escaping). If you unexpectedly see \uXXXX escape sequences, it's because: ① the input JSON already used Unicode escapes; ② you clicked the "Chinese → Unicode" button at the bottom. Use the "Unicode → Chinese" button to reverse the conversion, or replace the \uXXXX sequences with real Chinese characters in the source JSON.
Browser lags when converting very large files?
The tool is optimized for real-time conversion (with a 500ms debounce), but very large files (>1MB, hundreds of thousands of lines) can still strain it. Suggestions: ① Use the JSON formatter tool to validate the JSON first; ② Confirm it's a single large JSON rather than several independent JSON blobs concatenated; ③ For very large config files (10MB+), use command-line tools such as yq or kubectl convert; ④ If the browser freezes, close extra tabs to free memory and try again.
Glossary
- YAML
- YAML Ain't Markup Language (a recursive acronym) — a human-readable data serialization format that is the de facto configuration language for DevOps tools like Kubernetes, Docker Compose, and Ansible.
- Indentation
- YAML uses indentation (must be spaces, never Tabs) to indicate hierarchy. Indentation errors are YAML's most common pitfall — they cause parse failures or change the meaning of the config.
- Sequence
- YAML's array representation. Each element is denoted with - item, equivalent to a JSON array.
- Mapping
- YAML's object representation. Each key-value pair is denoted with key: value, equivalent to a JSON object.
- Block Scalar (|)
- YAML's multi-line string style. Denoted by the | symbol, it preserves all line breaks and indentation — equivalent to a heredoc.
- Folded Scalar (>)
- YAML's multi-line string style. Denoted by the > symbol, single line breaks are replaced by spaces, and only double line breaks are preserved as paragraph separators.
- Anchors and References
- YAML uses &name to define an anchor and *name to reference the same config block, avoiding duplication. Common in K8s where the same Secret is referenced in multiple places.
- YAML 1.2
- The current stable YAML specification (released in 2009, with minor revisions in 2021). This tool strictly follows this version (yaml.org/spec/1.2.2).
- Multi-document YAML
- YAML supports multiple documents in a single file, separated by the --- delimiter. A single Kubernetes YAML file can contain multiple resources such as Deployment + Service + ConfigMap.
- Kubernetes YAML
- The YAML format for Kubernetes resource manifests. It must include four required fields — apiVersion, kind, metadata, and spec — and is the de facto standard for K8s deployment.
- Norway Problem (YAML 1.1)
- The YAML 1.1 specification interpreted values like NO / On / Off as the boolean false, causing country names to be parsed incorrectly. YAML 1.2 fixed this issue, and this tool outputs in compliance with the 1.2 specification.
- Docker Compose
- The configuration file for Docker's multi-container orchestration tool. Written in YAML, it defines sections like services, networks, and volumes — the de facto standard for containerized deployments.
JSON Type to YAML Syntax Mapping
This tool converts JSON types to YAML types using the following rules:
| JSON Type | YAML Syntax | Notes |
|---|---|---|
| string | name: "Alice" | YAML omits quotes by default; double quotes are required for strings with special characters |
| integer | port: 8080 | YAML automatically recognizes numeric types (no quotes) |
| float | ratio: 3.14 | Floats follow the same rules as integers — YAML auto-detects them |
| boolean | enabled: true | YAML uses lowercase true/false only; YAML 1.1 also supports yes/no |
| null | value: null or value: ~ | YAML uses null or the tilde (~) to represent empty values |
| array | - item1
- item2 | YAML uses a leading - for each element on its own line |
| object | key:
sub: value | Objects use key: value, with nesting expressed by indentation |
| object array | - name: a
- name: b | Arrays of objects use - followed by key-value pairs |
YAML String Styles Comparison
YAML supports 6 string styles. Choose based on your needs:
| Style | Syntax Example | Use Case |
|---|---|---|
Plain | name: Alice | Simple strings — the most common form |
Double quotes | name: "Alice" | Contains special characters, supports \n escapes |
Single quotes | name: 'Alice' | Literal strings, no escaping performed |
Block scalar | bio: |
line1
line2 | Preserves all line breaks and indentation (heredoc) |
Folded scalar | bio: >
line1
line2 | Single newlines become spaces; double newlines mark paragraph breaks |
Explicit tag | value: !!str 123 | Force a type, overriding default inference |
JSON to YAML Conversion Examples
YAML output for complex JSON structures:
| Structure | Example |
|---|---|
| JSON Input | {"name": "app", "port": 8080} |
| YAML Output | name: app
port: 8080 |
| JSON Input | {"server": {"host": "0.0.0.0", "port": 443}} |
| YAML Output | server:
host: 0.0.0.0
port: 443 |
| JSON Input | {"hosts": [{"ip": "10.0.0.1"}, {"ip": "10.0.0.2"}]} |
| YAML Output | hosts:
- ip: 10.0.0.1
- ip: 10.0.0.2 |
| JSON Input | {"spec": {"replicas": 3, "image": "nginx:1.25"}} |
| YAML Output | spec:
replicas: 3
image: nginx:1.25 |
Privacy & Security
All JSON parsing, YAML generation, string escaping, Unicode conversion, smart JSON repair, and file reading happen entirely in your browser's local JavaScript engine. Your JSON content and the generated YAML configuration are never transmitted to any server over the network, nor are they recorded or analyzed. You can safely convert JSON containing database passwords, API keys, or Kubernetes Secret configurations. Local history is stored only in your own browser's localStorage — clear your browser cache to delete it.
Authoritative References
- yaml.orgYAML 1.2 Official Specification
- yaml.orgYAML Official FAQ
- WikipediaYAML - Wikipedia
- KubernetesKubernetes YAML Official Tutorial
- DockerDocker Compose Official 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