YAML to JSON Converter

How to use 3 steps
  1. Paste your YAML or JSON.
  2. Pick the Direction and Indent; tick Sort keys alphabetically if wanted.
  3. Press Convert, then Copy or Download.
Converted

Conversion uses js-yaml’s default schema, which parses data only and never executes code. Under YAML 1.2 rules no, on and off stay strings rather than turning into booleans the way YAML 1.1 parsers treat them. A multi-document YAML stream separated by --- becomes a JSON array, one entry per document. Anything JSON cannot express — dates, custom tags, non-string keys — is reported rather than silently dropped.

How this tool works

YAML and JSON describe the same shapes — maps, lists and scalars — so converting between them is mostly a change of notation. The direction is detected from what you paste, or you can set it. Indentation is yours to choose for the YAML side, and keys can be sorted alphabetically, which is worth doing when the output is going into version control and you want a readable diff.

The conversion is not always symmetrical, and the tool says so rather than letting you find out later: YAML has types JSON does not, and anything that cannot survive is reported by path. Dates become strings, infinities become null, and anchors and aliases — YAML's way of reusing a block — are expanded into copies unless you keep them, because JSON has no equivalent.

What does not survive the round trip

  • Comments are lost, always: JSON has no comment syntax, so a YAML file's comments cannot come back. This is the usual reason a config converted and converted back is worse than it started.
  • Anchors and aliases expand: a block reused in three places becomes three copies. The data is identical and the file is longer and no longer shares a single definition.
  • YAML's unquoted booleans catch people out: words such as yes, no, on and off are read as booleans by older YAML parsers. Quote them when they are meant as words — the Norway problem, where the country code NO became false.
  • Indentation in YAML is structure: unlike JSON's braces, the nesting is the whitespace. A converted file with the wrong indent setting is valid and means something different.

Same shapes, different notation, not always symmetric

YAML and JSON both describe maps, lists and scalars, so most of what the [msm_tool slug="yaml-json-converter"] does is a change of notation rather than a change of meaning. The conversion is not perfectly symmetrical in both directions, though, and rather than letting that surface later as a surprise, anything that cannot survive the trip is reported by its path at the time it happens.

Comments never come back

JSON has no comment syntax at all, so a YAML file's comments have nowhere to go once converted — this is the ordinary reason a configuration file converted to JSON and back reads worse than it started, even though the data itself is unchanged.

Anchors and aliases expand into copies

YAML's mechanism for reusing a block in several places has no equivalent in JSON, so a block referenced three times becomes three separate copies in the output. The data itself is identical either way; what is lost is the single shared definition, along with the fact that editing one instance no longer updates the rest.

The Norway problem

Bare words such as `yes`, `no`, `on` and `off` are read as booleans by YAML, which is how a country code of `NO` becomes the boolean `false` rather than the two letters intended — a well-known enough trap to have its own name. Quoting a value that is meant to stay text, rather than leaving it bare, is what avoids it.

Indentation is structure, not decoration

Where JSON uses braces to mark nesting, YAML uses whitespace itself, so a file converted with the wrong indentation setting is still perfectly valid YAML — it simply means something different from what was intended. That makes indentation a semantic choice here, not a cosmetic one.

Choosing a format for configuration

YAML suits configuration that people actually edit by hand, since comments and readability are exactly what it offers over JSON. JSON is the better choice wherever a machine produces and consumes the file, since it has fewer surprises and nothing YAML-specific to trip over — dates becoming strings and infinities becoming null in the conversion are both reported rather than silently applied either way.

Frequently Asked Questions

Specific to the YAML to JSON Converter. Broader questions about this category are answered on the category page.

JSON has no comment syntax, so they cannot be represented. This is the main thing lost converting YAML to JSON and back.
They expand into copies, because JSON cannot reference a block. The data is the same; the file is longer and the shared definition is gone.
YAML reads bare yes, no, on and off as booleans, so NO becomes false. Quote it. This is well known enough to have a name — the Norway problem.
YAML where people edit it by hand, since comments and readability matter. JSON where a machine produces and consumes it, since it has fewer surprises.
Dates become strings and infinities become null. Anything affected is reported by path rather than being converted quietly.

Subscribe to receive notifications about new tools, features, and productivity tips.