YAML to JSON

Convert YAML data to JSON format instantly.

Any YAML: a mapping, a list, a single value, or several documents separated by ---. Comments, anchors and aliases, << merge keys, | and > blocks, flow style like [a, b] and {a: 1}, and tags such as !!str or CloudFormation's !Ref are understood. Numbers are written as they are in the YAML.

Worth a look

Rate this tool

How useful was this tool?

YAML to JSON Converter

Paste or type YAML into the box, load the Example, or Open a file. The JSON appears as you type, ready to Copy or Download .json.

Notes under Worth a look list everything worth knowing about the file: values that other YAML readers would see differently, anchors that were expanded, duplicate keys, and tags. The conversion runs in your browser, and nothing you paste or open leaves your computer.

Example

A service configuration that reuses shared settings with an anchor:

# Shared settings
x-defaults: &defaults
  restart: always
  logging:
    driver: json-file

services:
  web:
    <<: *defaults
    image: nginx:1.27
    ports:
      - 22:22
    environment:
      DEBUG: no
      PYTHON_VERSION: 3.10

The JSON, read by the YAML 1.2 rules:

{
  "x-defaults": {
    "restart": "always",
    "logging": {
      "driver": "json-file"
    }
  },
  "services": {
    "web": {
      "restart": "always",
      "logging": {
        "driver": "json-file"
      },
      "image": "nginx:1.27",
      "ports": [
        "22:22"
      ],
      "environment": {
        "DEBUG": "no",
        "PYTHON_VERSION": 3.10
      }
    }
  }
}

What happened:

  • The comment was dropped. JSON has no comments.
  • <<: *defaults was expanded. The shared restart and logging settings were copied into web.
  • 22:22 and no stayed text, under the current YAML rules.
  • 3.10 stayed a number, written exactly as in the file.

A note under the result adds the important part. Docker Compose, Ansible and other tools that use the older YAML 1.1 rules read this same file differently: 22:22 becomes the number 1342, and no becomes false. Switch on Read as YAML 1.1 to see the JSON those tools actually work with:

"ports": [1342],
"environment": {
  "DEBUG": false,
  "PYTHON_VERSION": 3.10
}

3.10 is a number under both rules. If you meant the text “3.10”, such as a version number, quote it in the YAML. Otherwise many programs will read it as 3.1.

YAML 1.2 or YAML 1.1?

YAML lets you write values without quotes, and the reader guesses the type from how they look. The current version, YAML 1.2, guesses conservatively. The older YAML 1.1 rules turn much more into booleans, numbers and dates, and they’re still used by PyYAML, Go’s YAML libraries, Docker Compose, Ansible and Kubernetes tooling. Examples:

  • no, off → false
  • 0777 → 511
  • 22:22 → 1342

The converter uses YAML 1.2 by default and lists every value that a YAML 1.1 reader would see differently. If you’re checking a file for one of those tools, switch on Read as YAML 1.1.

To write YAML that both kinds of reader agree on, quote those values in the file, or create it with JSON to YAML, which quotes them for you.

Numbers, dates and special values

  • Numbers are kept exactly as written. 1.50 stays 1.50, and long IDs keep every digit.
  • Hexadecimal and octal are worked out. 0x1F becomes 31, and 0o17 becomes 15.
  • .inf and .nan become null, with a note, because JSON has no way to write infinity or “not a number.”
  • Dates stay text in both readings. JSON has no date type, so 2024-06-01 comes through as the string "2024-06-01", exactly as written.

Anchors, aliases and merge keys

YAML can define a block once and reuse it:

  • &name marks a block.
  • *name repeats it.
  • <<: *name merges its keys into another mapping.

JSON has nothing like this, so the converter writes out every reused block in full. A note says how many anchors were expanded.

Merge keys are worth checking in other converters. Some don’t support them and leave a key literally named "<<" in the JSON, which the program reading it won’t understand.

Several documents in one file

Kubernetes manifests and many other files contain several YAML documents separated by ---. Under Several documents:

  • As a JSON array puts each document in a list, as one JSON file.
  • One JSON per line writes each document as its own line, a format called JSON Lines. The download is then named .jsonl.

Tags and CloudFormation

Standard YAML tags work: !!str, !!int, !!float, !!bool, !!binary, !!set, !!omap and !!pairs. For example, !!str 123 forces the value to be text.

AWS CloudFormation templates convert to their JSON form. CloudFormation’s short tags become the long form that JSON templates use:

YAML JSON
!Ref MyBucket {"Ref": "MyBucket"}
!GetAtt MyBucket.Arn {"Fn::GetAtt": ["MyBucket", "Arn"]}
!Sub "arn:aws:s3:::${MyBucket}/*" {"Fn::Sub": "arn:aws:s3:::${MyBucket}/*"}
!Join [",", [a, b]] {"Fn::Join": [",", ["a", "b"]]}

 

The other intrinsic functions, like !If, !Select and !FindInMap, convert the same way. So you can turn a YAML template into a JSON one that CloudFormation accepts.

Other tags are dropped, and the value is kept, with a note. Home Assistant’s !secret api_key, for instance, becomes the plain text "api_key".

When the YAML has a mistake

You get the line and column, an excerpt with the problem marked, and a plain explanation. The most common mistakes come with a hint:

  • Wrong indentation. A line that’s indented more or less than its neighbours belongs to a different level than you meant.
  • Tabs. YAML doesn’t allow tabs for indentation. Replace the tabs with spaces fixes the whole file in one click.
  • No space after the colon. key:value isn’t a key and a value. It’s read as the single text “key:value”. Write key: value.
  • Two pairs on one line, like a: 1 b: 2. Each pair needs its own line.
  • A missing colon after a key.
  • A list next to keys at the same level. A mapping can’t also contain - item lines at the same indentation.
  • An unclosed quote or bracket.
  • An alias without its anchor. *defaults was used, but &defaults was never defined, or was defined further down.

Show it in the text jumps to the problem.

Options

  • Indent: 2 spaces, 4 spaces, or None (one line) for the smallest output.
  • Several documents: as a JSON array, or one JSON per line.
  • Read as YAML 1.1: reads values the way PyYAML, Docker Compose, Ansible and Kubernetes tooling do.
  • Sort keys A to Z: handy for comparing two files.

FAQ

What happens to repeated keys?

The last value is kept, and a note names the key and the line where it repeats. YAML doesn’t allow repeated keys, so this is almost always a copy-paste mistake worth fixing in the file.

Can I paste JSON?

Yes. JSON is nearly always valid YAML, so it converts as it is, and a note points you to the JSON Beautifier if you only wanted to format it. If you paste XML, a note points you to XML to JSON.

Can I convert JSON back to YAML?

Yes, with JSON to YAML. Comments and anchors from the original file won’t come back, because the JSON no longer has them.

How do I check the JSON afterwards?

Browse it as a tree in the JSON Viewer, or check it with the JSON Validator after editing.

Is my data uploaded anywhere?

No. Everything happens in your browser, and nothing you paste or open is stored.

Note: All processing is done client-side. We do not store or see your data.

Contact

Missing something?

Feel free to request missing tools or give some feedback using our contact form.

Contact Us