Appearance

YAML to JSON Converter

/yaml-json-converter/

Related tools

Related posts

Comments

0/500

About this tool

Why you need to convert between YAML and JSON

YAML is the format of choice for configuration that people write and edit by hand: Kubernetes manifests, GitHub Actions workflows, Docker Compose files and Spring Boot's application.yml. It expresses structure through indentation and allows comments, which makes it pleasant to read. APIs that exchange data between programs, command-line tools like jq and most SDKs, on the other hand, expect JSON. That is why moving the same data between the two formats comes up so often in development work.

Read moreShow less

YAML 1.2, released in 2009, reworked the grammar so that YAML became a superset of JSON, which was its biggest change. As a result, most valid JSON can also be read as YAML. This tool converts YAML to JSON and JSON to YAML, showing the result as soon as you paste.

How the YAML to JSON converter interprets YAML 1.2

On the YAML side, the open-source yaml library (2.9.0) reads the input with the YAML 1.2 core schema, and the values are written as 2-space indented JSON with JSON.stringify. In the other direction, values read with JSON.parse are written as 2-space indented YAML without folding long lines, so long strings stay on one line. Multi-line strings are written in block style with the | indicator.

Under the 1.2 core schema only true and false (and case variants such as True and TRUE) are booleans. In the YAML 1.1 era, yes, no, on and off were booleans too, so a country code like country: NO turned into false, a pitfall widely known as the Norway problem. Here NO, yes and on all stay strings. A value like 22:30 was read in 1.1 as the base-60 number 1350, but here it is the string "22:30", and dates such as 2024-01-01 also come out as strings.

Numbers have their own traps. version: 1.10 is read as a number and becomes 1.1, and a postal code like zip: 01234 loses its leading zero and becomes 1234. 0o10 becomes octal 8 and 0x1F becomes hexadecimal 31. Infinity values such as .inf cannot be expressed in JSON, so they come out as null. Values that must remain strings need quotes in the YAML.

Converting YAML and JSON in different situations

When debugging Kubernetes or CI configuration, converting YAML to JSON makes an indentation mistake that put a value at the wrong level obvious from the brackets. It is especially useful for confirming that a key sits inside the object you expected and that a list was really read as a list.

When moving an API response or JSON configuration into a YAML-based tool, convert JSON to YAML. Keys keep their input order, and strings that would be read differently without quotes, such as 01234 or 1.10, are automatically wrapped in double quotes. You can paste the result as it is and add comments by hand.

The merge key commonly used in Docker Compose (<<: *defaults) is a YAML 1.1 extension, so in this 1.2-based tool it is not expanded and remains as a key named "<<". Anchors (&) and aliases (*) themselves are expanded normally, producing JSON with the referenced content copied in.

Differences and limits when converting YAML to JSON

YAML comments have no place in JSON, so they disappear in conversion. If you want to tidy indentation while keeping comments, the YAML Formatter is the better tool. If the input contains several documents separated by ---, the tool does not convert it and reports that there are multiple documents, so paste one document at a time.

When JSON is converted to YAML, strings like yes and NO are strings under 1.2 and are written without quotes. A parser that follows YAML 1.1 rules, such as Python's PyYAML, may read them as booleans, so check which parser will consume the file and add quotes yourself if needed.

Tabs used for indentation, or the same key appearing twice at one level, are errors in YAML and are reported with the line and column. Input that nests aliases to blow data up exponentially is a known memory exhaustion attack, so alias expansion is capped (maxAliasCount 100) and input beyond that is rejected. Conversion happens entirely in this browser and nothing is sent to a server.

FAQ

What happens to YAML comments when converting to JSON?

JSON has no comment syntax, so comments are dropped from the result. Use the YAML Formatter if you want to fix indentation while keeping comments.

Why don't yes, on and NO become true and false?

That is the YAML 1.2 rule. YAML 1.1 treated yes and on as true and no and off as false, but in 1.2 only true and false are booleans and the rest are strings. This is why the Norway problem, where the country code NO became false, went away in 1.2.

Why does version 1.10 become 1.1 and 01234 become 1234?

Unquoted values that look like numbers are read as numbers. Wrap values that must stay exactly as written, such as versions and postal codes, in quotes like "1.10" and "01234" in the YAML and they convert as strings.

Why isn't the Docker Compose <<: *anchor merge key expanded?

The merge key is a YAML 1.1 extension, so in this 1.2-based tool it stays as a "<<" key. Anchors and aliases themselves are expanded normally.

Can it convert multiple documents separated by ---?

No. Input with several documents produces an error, so split them and convert one document at a time.

Is the config file I paste sent to a server?

No. Conversion runs only in this browser, so configuration containing passwords never leaves your device. Your input and options are kept in this browser's localStorage so you can continue later, and Reset clears them.