Skip to content
DevTrove

JSON & Data

YAML ↔ JSON Converter

Convert YAML 1.2 to JSON and JSON back to YAML, with strict, documented rules for anchors, merge keys and numbers.

Runs in your browser

Direction

Press Ctrl+Enter (⌘+Enter on Mac) to convert.

How to use

  1. Choose a direction: YAML → JSON or JSON → YAML.
  2. Paste your YAML or JSON into the input box.
  3. Select Convert, or press Ctrl+Enter (⌘+Enter on Mac) in the input box.
  4. If the input is rejected, fix the reported line and column and convert again.
  5. Use Copy output to copy the result.

Which YAML is supported

The converter reads YAML 1.2 with the core schema. That means true and false are booleans, null, ~ and an empty value are null, and words such as yes, no, on and off are plain strings. Dates such as 2001-12-14 stay strings, and 0777 is the decimal number 777.

A document that starts with %YAML 1.1 is rejected, not converted. YAML 1.1 reads yes, on and 0777 differently, and converting such a file as if it were 1.2 would silently change values. Remove the directive, or write %YAML 1.2, if you want it read as YAML 1.2.

Only tags that JSON can represent are allowed: !!str, !!int, !!float, !!bool, !!null, !!map and !!seq. Tags such as !!binary, !!set, !!omap, !!timestamp and any custom tag are rejected rather than turned into something else. Comments, anchors and the original formatting are not kept in the JSON.

Anchors, aliases and merge keys

Aliases (*name) are replaced by a copy of the anchored value (&name), and merge keys (<<: *name) are applied: the keys of the merged mapping are added, and a key written next to the merge key wins. A merge key must be followed by a mapping, an alias to a mapping, or a list of those. A quoted key such as "<<" is an ordinary key.

An alias must come after its anchor, and an anchor cannot contain an alias to itself. One anchor may be used at most 1,000 times and the input may contain at most 5,000 aliases, so a small file cannot expand into a huge result.

Several documents and what a round trip keeps

YAML text may hold several documents separated by ---. They are converted to a JSON array with one item per document, and the page says so when it happens. A trailing empty document is ignored.

This is not lossless. A JSON array converts back to a single YAML sequence, not to several YAML documents. Anchors and comments are also gone after a round trip, because JSON cannot hold them. Key order is kept.

Keys, numbers and values JSON cannot hold

JSON keys are strings. A YAML key that is a number, true/false or null is converted to a string (1 becomes "1") and the page tells you. Keys that are lists or mappings are rejected. A mapping that has the same key twice is always rejected, including after conversion: 1 and "1" count as the same key, because one value would otherwise be lost.

Integers are exact, however long: 12345678901234567890 keeps every digit. Other numbers are normal JavaScript floating-point numbers (IEEE 754), so a decimal with more than about 17 significant digits is rounded, and 1.0 and 1e3 are written as 1 and 1000. The values .inf, .nan and numbers too large or too small to store cannot be written in JSON and are rejected.

JSON → YAML first checks that the input is strict JSON, so trailing commas, comments and single quotes are reported. Strings that another YAML reader could mistake for another type, such as "yes", "no", "on", "off", "null", "123" or "2001-12-14", are written in double quotes so they stay strings.

Limits and slow input

Input is limited to 500,000 characters, nesting to 64 levels and output to 2,000,000 characters. Larger results are never cut off: nothing is produced and the reason is shown.

Conversion runs in a background worker and is stopped after 5 seconds, so the page stays responsive. If your browser cannot start a worker, the tool shows an error instead of converting on the page itself. Support has only been checked in Chromium-based browsers; Firefox and Safari are not verified.

FAQ

Is my data uploaded?
No. Your data is processed in your browser. Your YAML and JSON are not sent to a server, not stored, and not added to the page URL.
Why was my YAML rejected when other tools accept it?
This converter is strict on purpose: it rejects duplicate keys, YAML 1.1 documents, tags and values that JSON cannot hold, and anchors that point back to themselves, instead of guessing. The message names the problem and, where possible, its line and column.
Can I convert Kubernetes or Docker Compose files?
Yes, if they only use the features above. Multi-document files such as Kubernetes manifests become a JSON array, and merge keys such as <<: *default are applied.
Are YAML comments kept?
No. JSON has no comments, so they are dropped when converting to JSON.