YAML to JSON Converter

Paste YAML to get JSON, or paste JSON to get YAML. Kubernetes multi-document files, anchors and merge keys are handled.

Paste your YAML or JSON

Converted YAML to JSON (1 document).

How to convert YAML to JSON

  1. Paste your YAML into the YAML box, or press Load sample. The JSON box fills in as you type, and Convert to JSON runs it on demand.
  2. Choose the JSON indent: 2 spaces (the default), 4 spaces, a tab, or minified on one line.
  3. Press Copy or Download .json to take the result.
  4. To go the other way, paste JSON into the JSON box and the YAML box updates. If the input has a mistake, the message under the boxes shows the line and column, and the other box keeps its last good result.

How the conversion works

The page reads your YAML with js-yaml 4.3.2 using the YAML 1.2 core schema, then writes it with JavaScript's JSON serializer. That has a few effects worth knowing:

Worked example

With the sample loaded, the tool shows this JSON (2 spaces). The version 1.0.0 is not a number, so it stays a string, while replicas: 3 becomes the number 3.

{
  "name": "My App",
  "version": "1.0.0",
  "environment": {
    "production": {
      "replicas": 3,
      "image": "app:latest"
    },
    "staging": {
      "replicas": 1
    }
  },
  "tags": [
    "web",
    "api",
    "backend"
  ]
}

Kubernetes and multi-document YAML

A file with --- separators holds several documents. The tool returns a JSON array with one item per document, so this pair of manifests becomes [{ "apiVersion": "v1", "kind": "Service" }, { "apiVersion": "apps/v1", "kind": "Deployment" }]. A single document is returned as it is, not wrapped in an array.

Limits and edge cases

JSON cannot hold whole numbers above 9,007,199,254,740,991 exactly, so the tool warns you and suggests quoting the value. The YAML values .inf and .nan become null. Duplicate keys in one mapping are an error, and tags such as !!binary or !!set are not supported. Long lines are not wrapped in the YAML output, and strings that look like other types, such as 'yes' or '123', are quoted so they read back as strings. Your text is converted in your browser and is not uploaded. To tidy either format on its own use the YAML formatter or the JSON formatter, and for other formats see XML to JSON and CSV to JSON.

Frequently asked questions

Is JSON valid YAML?

In almost every case, yes. YAML 1.2 was designed as a superset of JSON, so you can paste JSON into the YAML box and it parses as YAML.

Why did my comments disappear?

JSON has no comment syntax, so the converter drops YAML comments. Converting JSON to YAML cannot bring them back.

Why are some values quoted in the YAML output?

Without quotes, YAML would read values such as yes, 123, true, null or 2024-01-15 as another type. The converter quotes those strings so they stay strings.

How do I convert a Kubernetes manifest with several documents?

Paste the whole file, including the --- lines. The result is a JSON array with one item per document.

Why does a long number change when I convert it?

JSON numbers here are 64-bit floating point and keep about 15 to 17 digits. Put quotes around the number in the YAML to keep it as exact text.

Sources: YAML 1.2.2 specification, RFC 8259 (JSON), and js-yaml.