---
slug: yaml-to-json-converter
title: "YAML to JSON Converter"
category: developer
updated: 2026-11-18
canonical: https://calcseed.com/c/developer/yaml-to-json-converter/
html: /c/developer/yaml-to-json-converter/
---

# YAML to JSON Converter

Convert indentation-based YAML into valid, pretty-printed JSON. Fast, free and private.

## Formula

```text
indent &rarr; nesting  &middot;  key: value &rarr; "key": value
```

## Inputs

| Variable | Type | Unit | Default |
| --- | --- | --- | --- |
| YAML input | text |  | name: Ada
age: 36
languages:
  - JavaScript
  - Rust
active: true |

## Outputs

| Result | Format |
| --- | --- |
| JSON output | primary |
| JSON output | text |
| Error | text |

## How it works

### What this converter does

Paste a YAML document and the converter re-emits the same data as pretty-printed JSON with two-space indentation. The default sample — a name, an age, a two-item languages list and an active flag — comes out as one JSON object with the list expanded into a bracketed array of quoted strings. Keys keep their order, types are inferred, and the output is valid JSON you can feed straight to an API, a build script or a JSON validator.

### How the conversion works

YAML stores structure in leading whitespace, so the converter&rsquo;s first job is measuring it: each non-blank line gets an indentation count, comments are stripped (a # at line start or preceded by a space), and blank lines vanish. The parser then walks the lines top to bottom. A line containing key: value starts a map entry; a line starting with a dash starts a list item; a key with nothing after the colon claims the more-indented lines below it as its nested value, and the recursion repeats until the document is fully consumed.

The tree that comes out is serialized with JSON.stringify at two-space indent, so the bracket style, comma placement and quoting are exactly what any standard JSON pretty-printer produces. Empty input yields an empty object, {} rather than an error, and any structural problem surfaces as an error message instead of a silently wrong tree.

#### What gets converted

- Indented blocks become nested objects and arrays
- Scalar strings are inferred as strings, numbers, booleans or null
- Lists marked with dashes become JSON arrays
- Keys are emitted in the order they appear

### How scalar types are inferred

| YAML input | JSON output | Reason |
| --- | --- | --- |
| age: 36 | "age": 36 | Parses as a finite number |
| active: true | "active": true | Reserved boolean literal |
| note: null | "note": null | null or ~ becomes null |
| id: "36" | "id": "36" | Quotes pin it as a string |
| name: Ada | "name": "Ada" | Falls back to string |

The inference rule is strict: a bare scalar becomes a number only if it parses as a finite number, true or false only when written exactly so, and null when written null or ~. Everything quoted stays a string no matter what it contains, and anything else falls back to a string. That makes 12:30, no and 1.20 — the values YAML 1.1 parsers famously reinterpreted — safe here: without quotes they still pass the number test or land as strings, never as booleans.

### The default example, step by step

#### Walking the parse

The first two lines have values, so name becomes the string "Ada" — a bare word falls through every scalar test — and age becomes the number 36. The languages line ends in a bare colon, so the parser looks below: the two dash lines at deeper indentation form a list of two strings, ["JavaScript", "Rust"]. Finally active: true hits the boolean literal and emits true. The assembled object prints as six lines of JSON: name, age, languages with its two-element array, and active.

### Why convert YAML to JSON

JSON is the interchange format of APIs and browsers. Converting config written in YAML to JSON lets you feed it to tools, scripts and services that only accept JSON: a Kubernetes values file into a REST endpoint, a CI matrix into a test runner, a survey of settings into a script that reads process.env-style config. JSON.stringify output is also the easiest format to assert against in tests, because string comparison is deterministic where YAML formatting is not.

### Common mistakes when converting

- Relying on anchors and aliases (&base and *ref) — this parser does not expand them, so the anchor text comes through as plain content
- Using multi-line block scalars (| and >), which have no equivalent in this converter&rsquo;s line-based model
- Expecting quoted YAML strings to keep their quotes in JSON — they do, but unquoted strings gain them, so name: Ada and name: "Ada" produce identical JSON
- Assuming tabs are illegal — this parser counts each tab as two spaces, which is more forgiving than strict YAML but can mask an indentation mistake
- Forgetting that a value of no or off is a string here, not a boolean, unless written as false

The anchor limitation is the one to check first when output looks wrong. A document using &defaults and *defaults to share a block will convert the anchor declaration itself into a key, leaving the alias unresolved. Expand anchors by hand before converting, or move the shared block into JSON with a script after conversion.

### Round-tripping between the formats

The sibling JSON to YAML converter runs the reverse pass, and a document that goes YAML &rarr; JSON &rarr; YAML keeps its data intact: key order, types and nesting all survive, with only formatting changing along the way. What cannot round-trip is anything YAML-specific — anchors, aliases, comments, multi-line block scalars — since JSON has no representation for any of them. Comments deserve a special warning: they are stripped during conversion, so a commented YAML config should be treated as YAML-only unless you re-add the explanations afterward. For pure data, though, the two formats are fully interchangeable, and this converter is the bridge in whichever direction the receiving tool requires.

## FAQ

### Can every YAML file become JSON?

Ordinary YAML maps, lists and scalars convert directly. Anchors, aliases and multi-line block scalars need manual handling first, since this parser does not expand them.

### How are numbers detected?

A scalar that parses as a finite number becomes a JSON number; quoted values always stay strings; true, false, null and ~ become their JSON equivalents.

### Is the key order preserved?

Yes. Keys are emitted in the order they appear in the YAML document, so the JSON matches the source line by line.

### What does the default example convert to?

An object with name "Ada", age 36, a languages array of "JavaScript" and "Rust", and active true — pretty-printed at two-space indent.

### Does the converter support tabs for indentation?

It tolerates them: each tab counts as two spaces of indent. Strict YAML forbids tabs entirely, so treat the tolerance as convenience, not permission.

### What happens to comments?

Lines with a # comment are stripped before parsing, and the comments do not survive into JSON. Keep a YAML copy if the explanations matter.

### Why is no converted as a string instead of false?

This parser only treats the exact literals true and false as booleans. Bare no and off are strings, which avoids the YAML 1.1 booleans-that-look-like-words problem.

### What happens with empty input?

The output is an empty JSON object, {}, rather than an error.

### Do quoted YAML strings stay quoted in JSON?

The values stay strings; JSON adds its own double quotes either way, so name: Ada and name: "Ada" produce identical output.

## Method and sources

Methodology: Conversions and formats follow the relevant IETF RFCs and IEEE standards, including RFC 4648 for Base64 and RFC 791 for IPv4 addressing.

Last updated: 2026-11-18.
- YAML 1.2 specification and JSON (RFC 8259) data model mapping.
