All tools

YAML ↔ JSON

Convert between YAML and JSON

Convert YAML to JSON and JSON to YAML, with multi-document YAML, anchors and aliases resolved, and precise error locations.

How to use YAML ↔ JSON

  1. Pick a Direction: YAML → JSON or JSON → YAML.
  2. Paste into the input, drop a file on it, or use Open file. Opening a .yaml/.yml or .json file picks the direction for you. Try an example fills in a sample.
  3. For YAML → JSON, choose the JSON indent and whether to convert All documents as an array when the input has several --- documents.
  4. For JSON → YAML, choose the Indent, the Line width at which long strings are folded (or No wrapping), and how Strings are quoted.
  5. Copy or download the result, or press Swap to turn the output into the new input and convert it back.

How it works

Both directions use the open-source yaml library, loaded on your first conversion. YAML is read with YAML 1.2 rules (the core schema): yes, no, on and dates stay strings, and 0o17 and 0x1F are numbers. Anchors and aliases (&name, *name) and merge keys (<<) are resolved, and duplicate keys are errors. Errors show their line and column; Jump to error in input moves the cursor there.

Some YAML has no JSON equivalent, and a notice says what changed. Non-string keys such as 200 or true, and map or list keys, become strings. Custom tags like !custom are ignored and the plain value kept. .inf and .nan become null. Comments are dropped. With All documents as an array, several documents become one JSON array; otherwise only the first is converted.

JSON → YAML parses the JSON with the browser’s standard parser and writes YAML with 1.1 quoting rules. So strings like "yes", "on" or "null" are quoted, and older YAML readers won’t turn them into booleans or null. Repeated objects are written in full, not as anchors. Conversion runs in the page as you type.

Limits

  • Input is limited to about 20 MB (20 million characters); opened or dropped files to 10 MB.
  • Alias expansion is limited (an alias count of 100, as measured by the YAML library) to stop “billion laughs” documents; one that goes over is reported as an error.
  • Numbers are JavaScript numbers in both directions, so integers beyond 2^53 lose precision (12345678901234567890 becomes 12345678901234567000).
  • YAML comments, custom tags and anchor names can’t be carried into JSON. JSON → YAML never produces comments or anchors.
  • Output longer than 1 million characters is only partly shown on screen; copy or download to get all of it.

Privacy

Conversion runs in your browser and files are read locally; nothing is uploaded or stored. The YAML library is part of this site and loaded from it. Share copies a link with your input and options in the URL’s # fragment; browsers don’t send that to servers, but anyone with the link can read it. Send to… passes the result through this tab’s session storage, removed as soon as the other tool reads it.

Frequently asked questions

Why did yes stay a string instead of becoming true?

YAML is read with YAML 1.2 rules, where only true and false are booleans. yes, no, on and off were booleans in YAML 1.1 only. When writing YAML, the tool quotes such strings so 1.1 readers (many CI tools, PyYAML) don’t misread them.

How are multiple YAML documents converted?

With All documents as an array on, every --- document becomes one item of a JSON array. With it off, only the first document is converted and a notice tells you how many there were.

Are anchors and merge keys supported?

Yes. Aliases are replaced by a copy of the anchored value, and <<: *defaults merges the anchored map into the current one, with keys written next to it taking priority. The status line shows how many aliases were resolved.

Why does my YAML say duplicate key?

A map has the same key twice. YAML forbids this and JSON would silently keep only the last value, so the tool reports it with its line and column instead of guessing.

Where did my comments go?

JSON has no comments, so YAML comments are dropped when converting to JSON. Converting back to YAML can’t restore them.

More tools