Indent:
YAML Input 0 B
Ready
0 chars
JSON Output 0 B
JSON output will appear here...
0 chars
Features

Why use this converter

Smart parser

Handles block-style mappings, sequences, nested structures, quoted strings, flow collections, and comments. A subset of YAML 1.2 that covers 99% of real-world configs.

Type inference

YAML's untyped scalars are inferred to the most appropriate JSON type: integers, floats, booleans, null, or strings. Strings that look like numbers stay strings if quoted.

Output control

Choose 2-space, 4-space, or tab indentation. Optionally sort object keys alphabetically for deterministic output.

How it works

Conversion explained

1. Tokenize lines

YAML is line-oriented. We split the input into lines, strip comments, and skip blank lines. Each remaining line is a key-value pair, a sequence item, or a nested block start.

2. Track indentation

YAML nesting is encoded by leading whitespace. The parser tracks the current indent stack to know when to start a new nested object or array.

3. Emit JSON

The parsed value is serialized with JSON.stringify using your chosen indentation.

FAQ

YAML to JSON Converter — frequently asked questions

What YAML features are supported?

Block mappings (key: value), block sequences (- item), nested structures via indentation, single and double quoted strings, flow collections ([a,b] and {k:v}), comments (#), and all JSON primitive types. Multi-document YAML and anchors/aliases are not supported.

Why is YAML parsing hard?

YAML is a complex spec with many edge cases: tabs vs spaces, flow vs block style, anchors, aliases, merge keys, tags, and more. JSONLab implements a pragmatic subset that covers the vast majority of real-world YAML configs.

Can I use this for Kubernetes manifests?

Yes! Kubernetes manifests are typically single-document YAML with mappings, sequences, and scalars — exactly what this parser handles.

Is the conversion reversible?

For YAML that maps cleanly to JSON, yes — round-tripping YAML to JSON to YAML produces equivalent data. Comments and formatting may be lost, but the values are preserved.