YAML to JSON Converter

Convert YAML to JSON or JSON to YAML in one box. Auto detect picks the direction, YAML errors name the line and column, and nothing leaves your browser. It is free and instant for config files, API payloads and CI pipelines.

YAML to JSON ConverterPrivate · runs on your device
Input
Words 0Characters 0Lines 0
Converted

Example: name: Ana age: 31 → { "name": "Ana", "age": 31 }

How to use the YAML to JSON converter

Paste either format and the converted text appears in the output as you type.

  1. Paste YAML or JSON into the Input box, or press Paste. Try it loads a short YAML example.
  2. Leave Direction on Auto detect, or force YAML to JSON or JSON to YAML. Auto detect treats text that starts with a brace or square bracket as JSON and everything else as YAML.
  3. Pick the Indent: 2 spaces, 4 spaces or Tab. YAML may not be indented with tabs, so Tab gives two spaces in YAML output and real tabs in JSON output.
  4. Check the status line. It shows "YAML → JSON" or "JSON → YAML", or an error such as "Invalid YAML" with a line and column.
  5. Press Copy or Download .txt. Use as input sends the result back into the input box, which is handy for a round trip.

The work is done by js-yaml 4.1 inside your browser, so deployment settings, URLs and secrets in your YAML are not uploaded. One trap: YAML written in flow style, such as {a: 1, b: [x, y]}, starts with a brace, so Auto detect reads it as JSON and reports an error. Choose YAML to JSON for that kind of input.

How YAML values become JSON types

For the example name: Ana and age: 31, the output is an object with the string "Ana" and the number 31. The number is a number because it is unquoted; writing age: "31" would give a string. Other plain values are interpreted too, and a few results surprise people:

YAML valueJSON result
yes, on, NOstrings: "yes", "on", "NO"
true, Truetrue
~ or an empty valuenull
2024-01-05"2024-01-05T00:00:00.000Z"
'2024-01-05' (quoted)"2024-01-05"
0x1F31
01010
1_0001000
.infnull, since JSON cannot hold infinity

The date row matters most. An unquoted date is read as a timestamp at midnight UTC, so quote it whenever you want the text unchanged. Older YAML 1.1 tools read yes and no as booleans, so quote those words if another parser will consume the same file.

Comments, anchors, errors and multiple documents

YAML can express things JSON cannot, so some of them change shape or are refused.

  • Comments are dropped, because JSON has no comment syntax.
  • Anchors, aliases and merge keys are expanded. A map that uses <<: *base comes out with the base keys copied in, and every alias becomes a full copy.
  • A file with several documents separated by --- is refused with "expected a single document", so convert one document at a time.
  • Repeated keys in one map are an error ("duplicated mapping key") rather than a silent overwrite.
  • A tab in the indentation is reported as an error with its line and column, and so is a nested line that is not aligned with its siblings.
  • A block marked | keeps its line breaks, while one marked > folds them into spaces. Both keep a final newline.

Going the other way, JSON to YAML keeps key order and quotes any string that would otherwise be read as another type, so "yes", "123" and "2024-01-05" stay strings. Text with line breaks becomes a block, and long strings are folded near 120 characters. Empty objects and arrays are written as {} and [].

Choosing between the two formats

YAML suits files that people edit: Docker Compose, Kubernetes manifests, GitHub Actions workflows and OpenAPI descriptions. It allows comments and multi-line text, but indentation is syntax, and plain values are guessed at. JSON suits data passed between programs: every language reads it, and it has no indentation rules. A common routine is to keep the YAML in a repository and convert it to JSON for tools that only accept JSON.

After converting, the JSON formatter can sort the keys or minify the result, and the diff checker shows what changed between two versions of a file. Kubernetes Secret values are base64 text, which the Base64 encoder and decoder can read. Tabular data belongs in the CSV to JSON converter instead.

Quick answers

Frequently asked questions

The questions people ask most, answered in plain words.

Why did yes, no, on and off stay as strings instead of true and false?

This converter follows YAML 1.2 rules through js-yaml, where only true and false are booleans. Older YAML 1.1 parsers also treat yes, no, on and off as booleans, which is how the country code NO turned into false in many files. Quote those words if other tools will read the same file.

Why did my date turn into a long timestamp?

An unquoted date such as 2024-01-05 is read as a timestamp, and JSON has no date type, so it is written as a UTC date and time string. To keep exactly the text you typed, put the date in quotes in the YAML. Quoted dates come through as plain strings.

Are comments kept when I convert YAML to JSON?

No. JSON has no comment syntax, so comments are removed during conversion, and they cannot come back when you convert the JSON to YAML again. Keep the YAML as your source of truth, or store notes in a normal key such as description if they must travel with the data.

Why does Auto detect say invalid JSON for my YAML?

Auto detect treats any input that begins with a brace or square bracket as JSON. YAML written in flow style, like a map in braces without quoted keys, starts that way and fails the JSON parse. Set Direction to YAML to JSON and the same text converts correctly.

Why does my YAML fail with an indentation or mapping error?

The usual causes are a tab in the indentation, a nested line that is not aligned with its siblings, or a value containing a colon followed by a space without quotes. The message gives a line and column. Replace tabs with spaces and quote any text that contains a colon or hash sign.