How to convert JSON to YAML and YAML to JSON

One text box converts in both directions. YAML → JSON reads the input as YAML and prints the matching JSON; JSON → YAML reads strict JSON and writes it out as YAML. Those two buttons are the only controls, so the direction is always explicit.

Both parsers ship with the page and run in this tab. Nothing is uploaded, the conversion still works with the network disconnected once the page has loaded, and the text stays on your machine.

  1. Paste or type JSON or YAML into the field. The placeholder reads “Enter YAML or JSON”.
  2. Press YAML → JSON to read the input as YAML and print JSON indented with two spaces.
  3. Press JSON → YAML to read the input as strict JSON — double-quoted keys, no comments, no trailing commas — and print YAML.
  4. Read the line above the result: it names the direction and the number of documents, or shows the parser message with the line and column of the first error.
  5. Copy takes the exact text of the result; Clear empties both boxes before the next document.

What each direction accepts

JSON → YAML uses the browser’s JSON parser, so the input has to be valid JSON: double-quoted keys, no comments, no trailing commas and no unquoted values. The YAML is written by the YAML 1.2 emitter that ships with the page — two-space indentation, “|-” block scalars for strings that contain line breaks, and quotes only where the value would otherwise change type.

YAML → JSON reads the 1.2 core schema. true and false are booleans, while yes, no, on and off stay text; 0x1F and 0o17 are numbers and 1_000 stays a string; a date such as 2024-01-02 stays the string “2024-01-02” instead of turning into a timestamp. The result is JSON indented with two spaces.

Anchors, merge keys and several documents

Aliases and merge keys are resolved while reading. A map that shares “base: &b” with “<<: *b” arrives in JSON with the inherited keys written out, so no literal “<<” key is left behind. JSON cannot express anchors, so a round trip gives an ordinary object instead.

Documents separated by “---” are converted one by one, in order. Three documents produce a JSON array with three entries and the status line reports “3 documents”; if one of them cannot be parsed, the message names that document and the result box is emptied.

Numbers, repeated keys and large results

Repeated keys are treated differently by the two formats: JSON keeps the last value without a word, while YAML input with a duplicate key is refused with a message. Integers outside ±9007199254740991 cannot be stored exactly in JavaScript, so they are rounded to the nearest representable value and the status line reports how many; .inf, -.inf and .nan cannot be written in JSON and become null, also reported.

A parse error clears the previous result instead of leaving it on screen, so an old conversion can never be copied by mistake, and an empty field is answered with a prompt rather than a conversion. Results longer than about 100,000 characters are printed without syntax highlighting: the text is complete, and skipping the colouring is what keeps a several-hundred-kilobyte document from freezing the tab.

Recent tools: