Skip to main content

YAML ⇄ JSON Converter

Convert YAML to JSON and JSON back to YAML in your browser.

YAML ⇄ JSON Converter
Indent
Paste some YAML...

Handles nested maps, sequences, block scalars and inline flow style, with a key count.

Convert between YAML and JSON in either direction, with the indentation you choose. Useful when a tool speaks one format and your file is in the other, and when you want to see exactly what structure a piece of YAML actually describes.

YAML ⇄ JSON Converter: Features

Why YAML needs checking more than JSON does

YAML is designed to be pleasant to write, and that pleasantness comes from indentation carrying meaning. The cost is that a structure can be wrong without looking wrong: a key indented two spaces too far becomes a child rather than a sibling, and the file still parses. Converting to JSON makes the nesting explicit with braces and brackets, which is often the quickest way to confirm that a manifest describes what you intended.

What the converter handles

Nested mappings and sequences, inline flow style with braces and brackets, block scalars in both the literal and folded forms, quoted and unquoted strings, inline comments, anchors, aliases and merge keys. Types are inferred by the YAML 1.2 rules, so numbers, booleans and null are typed while yes, no and dates stay strings. Going the other way, JSON is emitted as conventional block-style YAML with the indentation you select. The key count under the output is a quick sanity check that nothing was dropped.

The Norway problem and other surprising types

YAML infers types from unquoted values, and the rules have caught out a great many people. In the original specification, the unquoted word no is a boolean, which famously turns the country code for Norway into false. Similarly, a version number written as 1.10 becomes the number 1.1, and a value like 08 can be rejected as an invalid octal. The fix in every case is to quote the value. Converting to JSON shows you immediately how a value was read. This converter follows YAML 1.2, where no stays a string; tools that follow the older rules, such as PyYAML and therefore Ansible, still read it as false.

Where each format belongs

YAML wins for anything a person edits by hand: it allows comments, avoids the punctuation noise, and handles multi-line strings gracefully, which is why Kubernetes manifests, CI pipeline definitions and Docker Compose files are written in it. JSON wins for anything a machine produces or consumes: it is unambiguous, parses fast, has one obvious representation, and cannot express the alias and anchor features that make YAML hard to reason about.

Kubernetes manifests stay on your machine

Parsing and serialisation run as JavaScript in your browser. Manifests naming internal services, pipeline files containing secret references and configuration for unreleased systems are all safe to paste, because nothing is transmitted, stored or logged. To convert to or from other configuration formats, the TOML, CSV and XML converters work the same way.

YAML ⇄ JSON Converter: FAQ

Why did my value change type?

Because YAML infers types from unquoted scalars. The words true, false, yes, no, on and off can all become booleans depending on the specification version; the word null and an empty value become null; and anything that looks numeric becomes a number, which strips leading zeros and trailing zeros after a decimal point. Quote the value if you need it to stay a string.

Are comments preserved?

No, and they cannot be. JSON has no syntax for comments, so converting YAML to JSON discards them. That is worth remembering before you treat a converted file as a replacement for the original: convert for inspection or for feeding a tool, and keep the commented YAML as the version you edit.

Does it support anchors and aliases?

Yes. Anchors and aliases, the ampersand and asterisk syntax used to reuse a block, are expanded, and so are merge keys (<<), which Docker Compose files often use to share settings between services. The JSON shows every reused block written out in full, which is a quick way to see what each service actually ends up with.

Can I convert a multi-document YAML file?

Files that separate several documents with three hyphens are common in Kubernetes, where one file holds a Deployment and a Service. JSON has no equivalent of the document separator, so convert one document at a time. Splitting on the separator first is the usual approach.

Why does my converted YAML look different from what I wrote?

Because the output is generated from the parsed structure rather than from your text. Quoting style, flow versus block style, line wrapping and comments are all presentation choices that do not survive a round trip. The data is the same; the formatting is normalised.

Does the key count mean anything?

It counts the keys in the parsed structure, including nested ones, which makes it a quick check that the whole document came through. Duplicate keys are not allowed in YAML, so a repeated key is reported as an error with its line number rather than silently resolved.

Is it safe to paste a Kubernetes manifest with secret references?

Yes. Everything is parsed in your browser and nothing is transmitted, stored or logged. Note that a Kubernetes Secret stores its values as Base64, which is encoding rather than encryption, so anyone who has the manifest has the value regardless of which tool they open it in.

How to Use YAML ⇄ JSON Converter

  1. YAML to JSON, or JSON to YAML

    Select YAML to JSON or JSON to YAML. The Swap button moves the current output into the input and flips the direction, which is the fastest way to check that a document survives a round trip.

  2. Paste the YAML or the JSON

    Put the YAML or JSON into the input box. Conversion happens as you type, and a parse error is reported with the message from the parser rather than being silently ignored.

  3. Set the indentation and copy the YAML

    Pick the indentation for the output, then copy it with one click. The key count underneath is a quick check that the structure came through complete.

Category Data Formats