YAML ⇄ JSON Converter

Convert YAML to JSON or JSON to YAML instantly in your browser. Upload a file, see parse errors with line numbers, then copy or download the result.

Advertisement

Free YAML to JSON Converter (and JSON to YAML)

Paste YAML and get JSON, or flip the mode and paste JSON to get YAML. Conversion happens as you type, entirely in your browser — nothing is uploaded and nothing is stored. You can also load a file directly (.yml, .yaml, .txt, or .json), copy the output to the clipboard, or download it. A Load Sample button drops in a small working document in either direction if you just want to see the shape of the output.

When the input will not parse, the parser’s own error message is shown with the line and column, which is usually enough to find an inconsistent indent or a stray tab. When it does parse, a small summary reports whether the top level is an object or an array and how many keys or items it has — a quick sanity check that you converted the document you meant to.

Where This Gets Used

Almost every configuration format in modern infrastructure is one of these two. Kubernetes manifests, GitHub Actions workflows, Docker Compose files, Ansible playbooks, OpenAPI specifications, and CI pipeline definitions are YAML. APIs, log pipelines, package manifests, and most tooling that speaks over the wire are JSON. Converting between them comes up constantly:

  • Pasting a Kubernetes manifest into a tool or API that only accepts JSON.
  • Turning a JSON API response into readable YAML for a config file or documentation.
  • Checking that a hand-written YAML file parses to the structure you think it does — the fastest way to catch a wrongly indented block is to look at the JSON.
  • Converting an OpenAPI document between the two formats a generator supports.
  • Reformatting a dense one-line JSON blob into something a human can review in a pull request.

How to Use It

  1. Pick a direction — YAML to JSON, or JSON to YAML.
  2. Paste or upload. The file picker accepts the extensions appropriate to the current mode.
  3. Read the output. It updates as you edit the input. JSON is pretty-printed with two-space indentation; YAML is emitted with two-space indentation and lines folded at 120 characters.
  4. Check the structure summary to confirm the top-level type and the key or item count.
  5. Copy or download the result.

The Relationship Between the Two Formats

YAML 1.2 is formally a superset of JSON: every valid JSON document is also valid YAML, which is why you can paste JSON into a YAML file and it works. The reverse is not true, and the parts of YAML that JSON lacks are exactly the parts that need care in a conversion:

FeatureYAMLJSONWhat happens on conversion
Comments# to end of lineNoneSilently discarded — the biggest practical loss
Anchors and aliases&name / *nameNoneExpanded in place; the shared reference becomes duplicated data
Multiple documents--- separatorsOne value per documentRejected — convert one document at a time
Multi-line strings| literal, > foldedEscaped \nPreserved in meaning, not in style
Non-string keysAllowedStrings onlyCoerced to strings
TimestampsNative typeNoneEmitted as an ISO 8601 string
Trailing commasN/AIllegalA common cause of JSON parse errors

Comments are worth dwelling on. If you round-trip a heavily annotated Kubernetes manifest through JSON and back, every explanatory comment is gone and no error is raised. Convert a copy, not the file your team maintains.

Anchors and aliases behave the way most people want but not the way the source document said. Given:

defaults: &defaults
  retries: 3
staging:
  <<: *defaults

the alias is resolved and the values are written out in full at each use site. The output is correct; it is just no longer DRY, and editing one copy no longer changes the other.

Type Coercion: the Conversions That Bite

YAML infers types from unquoted scalars, and that inference is where silent data corruption comes from. The parser used here follows the YAML 1.2 core schema, which is stricter than the old 1.1 behaviour but still has sharp edges. Some real results:

YAML inputJSON outputNote
zip: 02134"zip": 2134Leading zeros are lost — the classic postcode and account-number bug
version: 1.20"version": 1.2Trailing zero gone; a version string became a number
id: 1234567890123456789012345678901234567000Beyond the safe integer range for a double, precision is lost
count: 1_0001000Underscore digit separators are accepted
date: 2026-08-12"2026-08-12T00:00:00.000Z"Parsed as a timestamp, emitted as ISO 8601 in UTC
value: ~null~, null, and an empty value are all null

The fix in every case is the same: quote it. zip: "02134" stays a string, version: "1.20" stays a string, id: "12345678901234567890" keeps every digit. If a value is an identifier rather than a quantity you intend to do arithmetic on, quote it as a matter of habit.

One historical hazard that does not apply here is worth mentioning because so much advice still warns about it. Under YAML 1.1, unquoted no, yes, on, and off were booleans, which is how the country code for Norway famously became false. The 1.2 core schema recognises only true and false (in any capitalisation), so country: no converts here to the string "no". Other parsers in your pipeline may still use 1.1 rules, so quoting remains the safe habit — but this converter will not do that to you.

Duplicate keys are rejected rather than silently overwritten. x: 1 followed by x: 2 produces a parse error naming the line, which is a feature: in a long manifest, a duplicated key where the second quietly wins is a genuinely hard bug to find by eye.

Reading Parse Errors

YAML errors almost always come from one of a handful of causes:

  • Tabs. YAML forbids tab characters for indentation outright. If an editor inserted one, the message will point at a line that looks perfectly fine.
  • Inconsistent indentation. Sibling keys must line up in the same column. Two spaces here and three there is a structural change, not a formatting preference.
  • A missing space after a colon. key:value is a single scalar; key: value is a mapping.
  • An unquoted string starting with a special character*, &, @, %, {, [, or a leading - followed by a space — which the parser reads as syntax.
  • A colon inside an unquoted value, such as a bare URL or a Windows path, which looks like a nested mapping.

JSON errors are narrower and usually one of: a trailing comma before } or ], single quotes instead of double quotes, unquoted keys, a comment (JSON has none), or curly “smart” quotes pasted from a document. The reported position is generally accurate; look just before it.

Output Formatting

JSON output uses two-space indentation, which is what most linters and diff tools expect. YAML output uses two-space indentation, folds long lines at 120 characters, and expands aliases rather than emitting anchors. That last choice means the YAML you get back is always self-contained — useful when it is going somewhere that may not resolve references, and something to be aware of if you were relying on the anchor for maintainability.

Long single-line strings are emitted in folded block style (>-) rather than as one very long line. The parsed value is identical; only the presentation differs.

Related Tools

For JSON alone, the JSON formatter and validator handles pretty-printing, minifying, and validating. The CSV to JSON converter covers tabular data. If the YAML in question is a Kubernetes workload definition, the Kubernetes manifest validator checks it against the schema and flags security issues, and the Dockerfile generator produces the image those manifests will run.

Frequently Asked Questions

Is my data uploaded anywhere?

No. Parsing and serialisation both run in your browser. Files you select are read locally and never leave the machine, which makes the tool safe for configuration containing internal hostnames or infrastructure detail.

Are comments preserved when I convert YAML to JSON?

No, and they cannot be — JSON has no comment syntax. They are discarded without warning. Round-tripping an annotated file through JSON and back will strip every comment, so work on a copy.

Why did my leading zeros disappear?

An unquoted 02134 is parsed as the number 2134. Quote any value that is an identifier rather than a quantity: "02134". The same applies to version strings such as 1.20, which otherwise becomes the number 1.2.

Does this convert multi-document YAML files?

No. Files containing several documents separated by --- produce an error saying a single document was expected. Split them and convert each in turn, or wrap them in a JSON array manually afterwards.

What happens to anchors and aliases?

They are resolved and the referenced values are written out in full wherever they were used. The data is correct but no longer shares a single definition.

Does unquoted “no” become false?

Not here. This converter follows the YAML 1.2 core schema, in which only true and false are booleans, so no stays the string "no". Older 1.1 parsers elsewhere in your toolchain may still coerce it, so quoting remains a sensible habit.

What happens to duplicate keys?

Conversion fails with an error naming the line, rather than silently keeping the last value. That is intentional — a duplicated key in a long file is a bug worth surfacing.

How large a file can I convert?

There is no hard limit, but everything runs on the browser’s main thread, so multi-megabyte documents can make the page pause while parsing. For very large files a command-line tool is a better fit.

Why is my JSON invalid when it looks fine?

The usual suspects are a trailing comma, single quotes instead of double quotes, unquoted keys, or curly quotes pasted from a word processor. The error message gives a position — look immediately before it.

Can I control the indentation of the output?

Not currently; both formats are emitted with two-space indentation, which matches the prevailing convention for Kubernetes, GitHub Actions, and most linters. Reindent afterwards if your project uses a different style.

Understanding YAML and JSON

YAML (YAML Ain't Markup Language) and JSON (JavaScript Object Notation) are two of the most popular data serialization formats used in modern software development. While both serve similar purposes, they have distinct characteristics that make them suitable for different use cases.

What is YAML?

YAML is a human-friendly data serialization format defined by the official YAML 1.2.2 specification. It uses indentation-based syntax to represent structure, making it exceptionally readable for configuration files, CI/CD pipelines, and infrastructure-as-code templates. YAML supports features like comments, anchors, and aliases that enhance maintainability.

What is JSON?

JSON is a lightweight data interchange format standardized by RFC 8259 and ECMA-404. It uses a bracket-and-brace structure that is easy for machines to parse and generate. JSON is the backbone of modern web APIs and is natively supported in virtually all programming languages.


How the Conversion Works

This tool performs bidirectional conversion between YAML and JSON formats entirely in your browser using the industry-standard js-yaml library:

  • YAML to JSON: Parses YAML syntax, resolves anchors and references, and serializes the data structure as formatted JSON with 2-space indentation.
  • JSON to YAML: Parses JSON syntax and converts it to clean, readable YAML format with consistent indentation and a 120-character line width.
  • Privacy-First: All processing happens client-side with no server uploads, ensuring your configuration data never leaves your device.

Common Use Cases

When to Convert YAML to JSON

  • API Integration: Most REST APIs require JSON format for requests and responses. Convert YAML configurations to JSON before sending to APIs.
  • CI/CD Pipelines: Many testing and deployment tools expect JSON input despite using YAML for configuration storage.
  • Performance-Critical Applications: JSON parsers are typically faster and more consistent across languages, making JSON better for high-throughput scenarios.
  • Browser Applications: JavaScript natively parses JSON, making it ideal for web applications and browser-based tools.

When to Convert JSON to YAML

  • Configuration Management: YAML's readability makes it superior for config files that humans edit frequently (Docker Compose, Kubernetes manifests, Ansible playbooks).
  • Documentation: YAML's comment support and cleaner syntax make it better for self-documenting configurations.
  • Version Control: YAML's minimal syntax creates cleaner git diffs, making code reviews easier.
  • Infrastructure as Code: Tools like Terraform, CloudFormation, and GitHub Actions prefer YAML for its human-friendly format.

Best Practices

For YAML

  • Use spaces, never tabs: YAML requires consistent indentation with spaces. Indentation errors account for ~70% of YAML issues.
  • Standard indentation: Use 2 spaces per indentation level for maximum compatibility.
  • Quote strings with special characters: Always quote strings containing colons, brackets, or other special characters to avoid parsing errors.
  • Validate before deploying: Use validation tools to catch syntax errors—they can reduce configuration errors by up to 50%.
  • Security: Use safe parsing modes (e.g., yaml.safe_load()) when processing untrusted input to prevent deserialization attacks.

For JSON

  • Validate syntax: Ensure all keys use double quotes and trailing commas are removed (not allowed in JSON).
  • Format for readability: Use indentation (2 or 4 spaces) for human-readable JSON files.
  • Minify for production: Remove whitespace from JSON sent over networks to reduce payload size.
  • Use schema validation: Implement JSON Schema to enforce data structure and catch errors early.

Common Pitfalls to Avoid

⚠️ YAML Pitfalls

  • Tab characters: YAML parsers reject tabs—use spaces exclusively.
  • Inconsistent indentation: Mixing 2-space and 4-space indentation causes parsing failures.
  • Unquoted strings: Values like yes, no, on, off are interpreted as booleans—quote them if you need strings.
  • Anchor/alias errors: Ensure all aliases (*anchor) reference defined anchors (&anchor).

⚠️ JSON Pitfalls

  • Single quotes: JSON requires double quotes for all strings and keys.
  • Trailing commas: JSON syntax forbids trailing commas after the last element in objects or arrays.
  • Comments: JSON does not support comments—remove them before parsing.
  • Undefined/NaN values: These JavaScript values are not valid JSON—use null instead.

Format Comparison

FeatureYAMLJSON
Readability⭐⭐⭐⭐⭐ Excellent for humans⭐⭐⭐ Good with formatting
Parsing Speed⭐⭐⭐ Slower due to complexity⭐⭐⭐⭐⭐ Fast and consistent
Comments✅ Supported with #❌ Not supported
Data TypesRich (dates, null, custom)Basic (string, number, boolean, null)
File SizeLarger (more whitespace)Smaller (compact syntax)
Use CasesConfig files, IaC, CI/CDAPIs, data exchange, web apps

Source: AWS - YAML vs JSON Comparison


Additional Resources

Frequently Asked Questions

What is the difference between YAML and JSON?+

YAML and JSON are both data serialization formats commonly used in configuration files and APIs. JSON uses braces, brackets, and quotes with a strict syntax, while YAML uses indentation and is more human-readable. YAML supports comments and multi-line strings, making it popular for configuration files like Kubernetes manifests.

How do I convert YAML to JSON?+

Select the YAML to JSON mode, then paste your YAML content into the input panel or upload a .yml or .yaml file. The tool automatically converts your input and displays the JSON output in the right panel. You can then copy the result to your clipboard or download it as a .json file.

What file size limit applies to uploads?+

The tool supports file uploads up to 10MB in size. This is sufficient for most configuration files and data exports. If your file exceeds this limit, consider splitting it into smaller sections or removing unnecessary data before conversion.

Why am I getting a conversion error?+

Common errors include inconsistent indentation in YAML (always use spaces, not tabs), missing quotes around special characters, or invalid JSON syntax like single quotes instead of double quotes. The error message will indicate the specific issue. Try the Load Sample button to see correctly formatted examples.

Is my data secure when using this converter?+

Yes, all conversion processing happens entirely in your browser using JavaScript. Your data is never sent to any server, making it safe to convert configuration files containing sensitive information like API keys or credentials. Clear your browser tab when finished for additional security.

What structure information does the tool show?+

After conversion, a statistics panel displays the data structure type (Object or Array) and details like the number of keys for objects or items for arrays. This helps you quickly verify that your data was parsed correctly before using the output.

This tool is provided for informational and educational purposes only. All processing happens in your browser — no data is sent to or stored on our servers. While we strive for accuracy, we make no warranties about the completeness or reliability of results.