Skip to main content

YAML to JSON

From config file to API payload.

Paste a Kubernetes manifest, a CI pipeline or any other YAML document and get formatted JSON back — ready to send to an API, load in code or explore in the viewer.

Anchors, aliases and merge keys are supported. Object-instantiating tags are rejected, and comments are dropped since JSON has no comment syntax.

Input YAML

Size: 269 BLines: 20

JSON output

Paste YAML to see the output.
Size: 0 BLines: 0

Every JSON file is YAML; the reverse is not true

YAML is a superset of JSON, so any JSON document is already valid YAML. Going the other way means deciding what to do with everything YAML has that JSON does not: comments, anchors and aliases, multiple documents in one file, multi-line block scalars, dates as a native type, and a set of untagged scalars whose type is inferred from how they are written.

That last one is where the surprises live. In JSON, "no" is unambiguously a string. In YAML, what no means depends on which version of the spec your parser implements — and parsers disagree.

What your values turn into

Here is exactly what this converter produces, value by value. Several of these differ from what other YAML tools will give you, which is precisely why it is worth seeing the real output rather than assuming.

YAML inJSON outNote
country: no"no"A string here — see the Norway note below.
enabled: yes"yes"Likewise a string, not true.
version: 1.01A float whose trailing zero has no JSON representation.
zip: 012341234The leading zero is gone. Postal codes need quoting.
octal: 0o1412Octal literal, converted to decimal.
hex: 0x1F31Same for hexadecimal.
when: 2024-01-01"2024-01-01T00:00:00.000Z"A plain date becomes a full timestamp in UTC.
big: 90071992547409939007199254740992Beyond 2^53 — precision is lost silently.
inf: .infnullInfinity and NaN have no JSON equivalent.
blank: or x: ~nullBoth are YAML nulls.
time_like: 12:30:00"12:30:00"Stays a string — not sexagesimal.
quoted: "no""no"Quoting always settles the question.

The Norway problem, and why it does not bite here

The famous case: a list of country codes containing NO for Norway, loaded by a YAML 1.1 parser, which reads no as boolean false. Norway disappears from the map.

This converter follows the YAML 1.2 core schema, where only true and false are booleans — so no, yes, on and off all stay strings, as the table above shows. That is the modern, correct behaviour.

It is still worth knowing about, because the file you convert here may be read elsewhere by something that implements YAML 1.1 — which includes PyYAML in its default configuration, and plenty of tooling built on it. A file that converts cleanly here can still be misread by the next tool in the chain. Quoting protects you from all of them.

Anchors, aliases and merge keys are resolved

YAML lets you define a block once and reuse it. JSON has no such concept, so the converter expands everything — the output contains the fully resolved values.

YAML
defaults: &defaults
  retries: 3
  timeout: 30
job_a:
  <<: *defaults
  timeout: 60
job_b:
  <<: *defaults
JSON
{
  "defaults": { "retries": 3, "timeout": 30 },
  "job_a":    { "retries": 3, "timeout": 60 },
  "job_b":    { "retries": 3, "timeout": 30 }
}

Note that job_a correctly keeps its own timeout: 60 — a merge key supplies defaults, it does not override what is written explicitly. The anchor definition itself remains in the output as an ordinary key, because it was an ordinary key in the source.

What gets rejected, and what it means

InputMessage
A tab used for indentation"Tab characters must not be used in indentation." YAML forbids tabs outright. The reported line number points at the offending line.
Two documents separated by ---"Expected a single document in the stream, but found more." JSON has no way to hold two documents — split the file and convert each part.
An unknown tag such as !!js/function"Unknown tag." Rejected rather than interpreted — see below.
Inconsistent indentationA parse error with the line, column and the text of the line itself.

Duplicate keys are the exception: a: 1 followed by a: 2 is accepted, and the last value wins. That matches JSON parsing behaviour, and it means a duplicated key in a long config file will not announce itself. Run the result through the analyzer if a value is not what you expected.

Why converting untrusted YAML is safe here

YAML deserialization has a genuinely bad security history. The dangerous pattern is a parser that instantiates arbitrary objects from tags — !!python/object/apply in PyYAML's unsafe loader is the classic remote-code-execution vector, and !!js/function was the JavaScript equivalent.

Two things prevent that here. The loader uses the default schema, and in js-yaml v4 the object-instantiating types were moved into a separate package that is not installed — so !!js/function produces "Unknown tag" rather than a function. And the conversion runs in your browser on a static page with no network call, so there is no server to compromise and no copy of your file anywhere.

Binary values (!!binary) are decoded and re-encoded as base64 strings, and native dates become ISO 8601 strings, so the JSON you get back is plain data with nothing exotic in it.

After converting

The output is formatted JSON, ready to send to an API or load in code. Two things are usually worth doing next: open it in the viewer to confirm the structure matches what you expected — deep YAML indentation hides mistakes that a tree makes obvious — and check the analyzer findings for fields that changed type unexpectedly.

If you need to go the other way, the JSON to YAML converter handles the return trip, with the caveat that comments cannot come back: they were discarded at parse time and nothing can reconstruct them.

Frequently asked questions

Are YAML comments kept?
No. JSON has no comment syntax, so comments are discarded during parsing. If the comments matter, keep the YAML file as the source of truth and treat the JSON as a build output.
Why did `no` stay a string instead of becoming false?
Because this converter follows the YAML 1.2 core schema, where only true and false are booleans. Parsers implementing YAML 1.1 — including PyYAML by default — do convert it, which is the well-known Norway problem. Quote values whose type matters.
Why did my leading zero disappear?
01234 is an unquoted number, so it converts to 1234. Write "01234" to keep it as a string. The same applies to version numbers such as 1.0, which otherwise become 1.
Can I convert a multi-document YAML file?
Not in one pass — a JSON document cannot hold several YAML documents. Split the file at the --- separators and convert each part, or wrap the results in an array yourself.
What happens to anchors and aliases?
They are resolved and expanded, so the JSON contains the fully materialised values. Merge keys work as expected: explicit values override the merged defaults.
Is the converter safe against malicious YAML?
Yes. The loader has no object-instantiating types — tags like !!js/function are rejected as unknown rather than executed — and the conversion runs entirely in your browser, so nothing is uploaded and there is no server to attack.
Why does it reject tab characters?
The YAML specification forbids tabs in indentation, so this is the parser enforcing the spec rather than a limitation. Replace them with spaces; the error message gives you the line.