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 the first time you convert. YAML is read with YAML 1.2 rules (the core schema), so yes, no and on stay strings, dates stay strings, and 0o17 and 0x1F are numbers. Anchors and aliases (&name, *name) and merge keys (<<) are resolved, and duplicate keys are reported as errors. Errors show their line and column, and Jump to error in input moves the cursor there.

Some YAML has no JSON equivalent, and a notice says what was changed. Non-string keys such as 200 or true become string keys, and map or list keys are turned into strings. Custom tags like !custom are ignored and the plain value is kept. .inf and .nan become null. Comments are dropped. Several documents become one JSON array with All documents as an 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 out in full rather than 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 happens entirely in your browser and files are read locally; nothing is uploaded or stored. The YAML library is part of this site and is loaded from it. Share copies a link with your input and options in the URL’s # fragment, which browsers don’t send to servers, though anyone with the link can read it. If you use Send to… to open the result in another tool, it is handed over through this tab’s session storage and removed as soon as that 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