Skip to main content

YAML to JSON Converter

Convert YAML to JSON format instantly.

Reviewed by · Last reviewed

How to Use the YAML to JSON Converter

  1. Paste YAML into the input pane. Docker Compose files, GitHub Actions workflows, Kubernetes manifests, Ansible playbooks, and .yml configs from Rails, Django, or Hugo all work.
  2. Pick an output style: 2-space JSON (most common), 4-space JSON (older Python style), or minified JSON on a single line (good for piping into another tool).
  3. Click Convert. Valid YAML becomes structured JSON on the right; malformed input gets an error message that points at the offending line.
  4. Copy the JSON with the clipboard button or drop it into the sibling JSON-to-YAML converter to round-trip and confirm semantics are preserved.

What It Does and How It Works

YAML is block-structured by indentation, which makes a simple parser more involved than it looks. The converter tokenises lines into one of four categories: block sequence items (starting with - ), block mapping entries (a key followed by :), scalar continuations, and structural markers (---, ...). Indentation is tracked with a stack of column offsets so nested sequences inside mappings and mappings inside sequences nest correctly. Scalar values are classified: unquoted tokens that match the YAML number grammar become JSON numbers, the literal tokens true, false, and null become the JSON equivalents, and everything else stays as a JSON string.

Once the input is parsed into a JavaScript object, JSON.stringify does the output formatting with the indent you selected. Quoted strings in the source (single or double) are always treated as strings regardless of content, which is how you preserve numeric-looking strings like ZIP codes or version numbers. Flow-style collections ({ key: value } and [ a, b ]) are handled alongside block style. Folded and literal block scalars (> and |) collapse or preserve newlines per YAML 1.2.

Real Use Cases

  • Copying a Kubernetes manifest into a tool that only accepts JSON API payloads, such as curl against /api/v1/namespaces.
  • Debugging a CI workflow by converting .github/workflows/ci.yml to JSON and viewing it in a JSON path explorer.
  • Feeding a config file into a JSON Schema validator that does not speak YAML natively.
  • Teaching the difference between YAML tag inference and explicit typing by seeing what JSON types fall out.
  • Embedding a small config snippet into JavaScript code that uses JSON.parse for portability.
  • Auditing a Helm chart or Terraform override.yml for hidden duplicate keys, which JSON forbids but some YAML parsers silently accept.

Edge Cases and Pitfalls

  • The Norway problem. YAML 1.1 famously parsed unquoted no as a boolean false, which caused country code "NO" to mean "disabled". YAML 1.2 removed these aliases, but many parsers are still in 1.1 mode. This converter follows YAML 1.2: only true, false, True, False, TRUE, and FALSE are booleans.
  • Tabs are illegal for indentation. YAML 1.2 mandates spaces. A hidden tab will either produce an error or silently misnest your tree. Convert tabs to spaces before pasting if your editor inserted them.
  • Multi-document files. YAML can contain several documents separated by ---. The converter uses the first document only; to convert all of them wrap them in a JSON array manually.
  • Anchors and references. &anchor and *ref are basic YAML features that this lightweight parser may flatten or drop depending on complexity. Very tight Helm templates that rely on anchors should be fully rendered first.
  • Null-valued keys. foo: with nothing after the colon is a key mapping to null, which round-trips through JSON as "foo": null. Some consumers expect the key to be absent instead - check both.

YAML 1.2 Specification in Brief

YAML is defined at yaml.org/spec/1.2.2. The key design goal is that any valid JSON document is also valid YAML, so YAML is a strict superset. The additions YAML brings are block indentation, comments (#), anchors and aliases, explicit tags (!!str, !!int), and folded/literal multi-line strings. The 1.2 revision tightened type inference to avoid the YAML 1.1 booleans-everywhere problem and made JSON explicitly a subset. The YAML test matrix tracks how different parsers handle the standard; notably, Python\'s PyYAML defaults to YAML 1.1 mode and go-yaml v2 had edge cases that v3 fixed.

When to Use Another Tool

For production conversion, use yq (Go or Python editions) on the command line; it handles anchors, merges (<<:), and multi-document files in full compliance with the spec. yq eval -o=json file.yml is a one-liner equivalent. Inside JavaScript, the js-yaml library is the de facto parser and supports both 1.1 and 1.2 modes. Python has ruamel.yaml, which preserves comments and ordering better than PyYAML. This web tool is faster than any of those for quick spot conversions, especially on a laptop without Node or Python at hand, but treat it as a viewer rather than a canonical converter for mission-critical configs.

Frequently Asked Questions

Which YAML version does the parser implement?

It targets YAML 1.2 semantics, which means it does not auto-cast <code>yes</code>, <code>no</code>, <code>on</code>, or <code>off</code> to booleans - a change from YAML 1.1 that eliminated the famous Norway problem. Only the literal tokens <code>true</code> and <code>false</code> are booleans. If you feed in a config originally written for a 1.1 parser, inspect the output to confirm those tokens are now strings.

Does the converter preserve key order?

Yes. JavaScript objects preserve insertion order for string keys per the ECMAScript specification, and <code>JSON.stringify</code> emits them in that order. So a Kubernetes manifest where <code>apiVersion</code> must appear before <code>kind</code> still looks right in the JSON output. That guarantee holds for every modern browser because the spec has required it since ES2015.

How are multi-line strings converted?

YAML literal block scalars introduced by <code>|</code> preserve newlines; folded scalars introduced by <code>&gt;</code> collapse line breaks into single spaces except around blank lines. Both end up as plain JSON strings with their preserved or folded whitespace baked in. JSON itself has no multi-line string syntax, so you will see <code>\\n</code> escapes in the output where your source had literal newlines.

Can I round-trip YAML to JSON and back without losing anything?

For most configs yes, but YAML features without JSON equivalents are lost. Anchors, aliases, explicit tags (<code>!!str</code>, <code>!!set</code>), comments, and the distinction between single-quoted and double-quoted strings all vanish in JSON. If you convert YAML to JSON and back through the sibling tool, you get a functionally equivalent but textually different file.

Is my YAML sent to a remote server?

No. The converter is a Preact component shipped with the page bundle that executes entirely on the main thread of your browser tab. There is no fetch call to a backend, no websocket, and no tracking of the content you paste. Because YAML often contains secrets (API keys in a Docker Compose file, credentials in an Ansible vault), that guarantee is important - nothing you put into the textarea leaves your machine.

Does it support multi-document YAML?

Only the first document separated by <code>---</code> is converted. Multi-document YAML is most common in Kubernetes manifests and <code>helm template</code> output. To convert them all, split the source on the document separator, convert each piece separately, and wrap the results in a JSON array. A future version may emit a JSON array automatically for multi-doc input.

How are duplicate keys handled?

YAML 1.2 forbids duplicate keys, and strict parsers reject the file. This converter is lenient: later occurrences overwrite earlier ones, matching the behaviour of PyYAML and go-yaml. This is the most common cause of subtle config bugs, so watch for keys appearing twice in long files.

Can I convert JSON back to YAML?

Not with this tool - the sibling JSON-to-YAML converter on the same site handles that direction. Both converters use independent implementations, so round-tripping through them is not guaranteed to produce byte-identical YAML; comments, anchor names, and quoting choices do not survive. Use command-line <code>yq</code> when byte-identical round trips matter.

What happens to YAML comments?

They disappear. JSON has no comment syntax, so the converter drops every line starting with <code>#</code> and every inline comment after a value. If your comments carry meaningful information (licensing, explanation of magic constants), copy them into the consumer file manually or migrate to a format like JSON5 or HJSON that permits comments.

Are tabs really forbidden in indentation?

Yes. YAML 1.2 explicitly lists the tab character as not allowed as leading whitespace for indentation. A file with a stray tab is technically invalid YAML, and different parsers react differently: some reject it, some silently promote the tab to some number of spaces. If conversion fails unexpectedly, search for tab characters in your source and replace them with spaces.

More Developer Tools