Skip to the tool
DevToolBench

YAML to JSON Converter

YAML into JSON, anchors resolved, errors with line numbers.

0 chars
Documents
—
Output
—
Characters
0
Valid YAML
—

Everything runs in your browser. Nothing you type is sent to a server.

Found a bug in this tool? Report it.

Share this tool

What the converter does

This YAML to JSON converter reads a YAML document and writes the equivalent JSON as you type, entirely in your browser. Anchors and aliases are resolved, merge keys are applied, block scalars are turned into ordinary strings with the right newlines, and a file with several documents becomes a JSON array. When the input is not valid YAML, the error names the line, which is usually the only thing you need to find a stray tab or a missing space. Most ways to convert YAML to JSON online send the file to a server first; this one never does.

It is a real YAML parser, written for this page, not a regular expression pass. It covers what configuration files actually use: block and flow mappings and sequences, plain, single-quoted and double-quoted scalars with every escape, | and > blocks with the strip and keep indicators, comments, anchors, aliases, the << merge key and --- document separators.

What it deliberately refuses

A partial YAML parser that silently returns something different is worse than none, so everything outside the supported subset is an error, not a guess. Custom tags such as CloudFormation's !Ref or !GetAtt stop the conversion, because their meaning lives in the application, not in YAML. So do !!binary, complex keys written with ? or as a list, and the %TAG directive. The one tag that is understood is !!str, which keeps 1.0 as text.

Numbers that JSON cannot hold exactly are refused too: .inf, .nan and integers beyond 2^53. Quote them and they come through as strings, digit for digit.

YAML 1.2, not 1.1

Values are typed with the YAML 1.2 core schema. true, false and null (or ~, or nothing at all) become JSON literals; 42, 0x1F, 0o17, 1.5 and 1e3 become numbers; everything else is a string. That differs from PyYAML, which implements 1.1: there no is false, 0755 is octal, and 2026-09-23 becomes a date object. Here the first stays the text no, the second is the decimal 755, and the date stays a string, which is also how JSON would carry it. If a file must mean the same thing to every parser, quote anything that could be read two ways.

YAML anchors and aliases

An anchor (&base) names a node and an alias (*base) repeats it. JSON has no references, so each alias is expanded into a full copy, and a file that reuses one block ten times produces ten copies. The merge key <<: *base copies the anchored mapping's keys into the current one; keys written explicitly win over merged ones, and with <<: [*a, *b] the first source wins over the second. This is the pattern Docker Compose files use for shared service settings, and it is where hand conversion usually goes wrong.

Going the other way

To turn the JSON back into YAML, with quotes wherever YAML would misread a value, use the JSON to YAML converter. The JSON formatter will validate and re-indent the output, and the JSON diff shows what changed between two converted versions of the same config.

Frequently asked questions

Why did yes and no stay as text instead of turning into booleans?

Because this parser follows the YAML 1.2 core schema, where only true and false (in three capitalisations) are booleans. The yes, no, on and off booleans belong to YAML 1.1, which PyYAML and some older tools still implement. If a value must be a boolean everywhere, write true or false and every parser will agree.

What happens to a file with several documents separated by ---?

Each document becomes one element of a JSON array, in the order they appear. A single document converts to its value directly, with no array around it. Anchors do not cross document boundaries, so an alias in the second document cannot point at an anchor defined in the first.

Which parts of YAML does this parser not support?

Custom and application tags such as !Ref or !!binary, complex keys (a list or mapping used as a key, or the ? indicator), and the %TAG directive. Each of those stops the conversion with an error that names the line, instead of producing JSON that quietly differs from what your application would load. The !!str tag is supported.

Why do I get an error about a number being too large?

JSON numbers are read as 64-bit floats almost everywhere, which hold integers exactly only up to 9,007,199,254,740,991. A longer ID would come out as a different number with no warning, so the converter stops and asks you to quote it. The same applies to .inf and .nan, which JSON has no way to write.

Is my YAML sent anywhere?

No. The parser is plain JavaScript running in this page, and the conversion happens as you type without a single network request. That matters for the files people usually paste here, which are CI pipelines, Kubernetes manifests and Compose files full of hostnames and, too often, secrets.

Related tools

Updated