Convert between JSON and YAML

Turn JSON into readable YAML or YAML back into JSON, with js-yaml doing the parsing and nothing leaving the tab.

Convert between JSON and YAML

0 characters

Three steps — nothing to install

  1. Paste JSON or YAML

    A config file, a Kubernetes fragment, or an API response.

  2. Pick the direction

    JSON to YAML or YAML to JSON, with a two- or four-space indent.

  3. Copy the result

    The library is fetched once, from this site, only when you press Run.

YAML is not JSON with fewer brackets

Every JSON document is valid YAML, which is why converting JSON to YAML is always safe. The reverse is not true. YAML has anchors and aliases, merge keys, multi-line strings, dates, binary values and tags, and only some of those have a JSON equivalent.

This converter resolves anchors and merge keys, so an alias becomes a copy of the value it pointed at. Tags that describe a type — !!binary, !!timestamp — are converted to strings or fail with an error rather than being silently dropped, because guessing would change the data.

What converts cleanly

Objects, arrays, strings, numbers, booleans and null round-trip. Key order is preserved from JSON in the output, because js-yaml writes in insertion order. Comments are not: JSON has none, and YAML comments are stripped when the document is parsed, so a conversion in either direction loses them.

Indentation is cosmetic in YAML but must be consistent. Two spaces is the common convention and what this tool writes; the parser accepts any consistent indent on input but not tabs, which are invalid in YAML indentation.

Limits worth knowing

A multi-document YAML file, separated by ---, is read as its first document. That is deliberate: merging documents into one JSON value has no obvious meaning, and silently taking the last would be worse. Split the file and convert the part you need.

The converter loads js-yaml, about 108 KB, from this site the first time you press Run; the page says so before you click. Your document is not sent anywhere — the library runs in the tab. For the other direction of the same job, JSON to CSV, see the CSV converter.

Frequently asked questions

Can it convert a multi-document YAML file?It reads the first document. Split the file on --- and convert the document you need.
Are comments preserved?No. JSON has no comments and YAML comments are dropped when parsed, in both directions.
Is my data uploaded?No. The library is downloaded from this site once, but the conversion itself happens in the tab.
How big is the library?About 108 KB, loaded only when you press Run.
Do anchors and merge keys work?Yes. Aliases are resolved into copies of the value, so the JSON contains the merged data.
Why does a date come out as a string?YAML can mark a value as a timestamp; JSON has only strings. The date text is kept rather than converted to a number.