How to use the yaml parser
- Paste or type your YAML content into the text area.
- The yaml parser processes the input automatically as you type.
- View the resulting JSON in the output panel below.
- Copy the JSON output for use in your application or configuration.
Supported YAML 1.2 Subset
This tool implements a practical subset of the YAML 1.2 specification. It parses block mappings (key-value pairs), block sequences (lists starting with hyphens), flow collections using square brackets and curly braces, plain unquoted scalars, single-quoted and double-quoted strings, literal block scalars introduced by a pipe character, folded block scalars introduced by a greater-than sign, and hash comments.
Features intentionally omitted include anchors, aliases, tags, merge keys, multi-document streams separated by triple dashes, and complex mapping keys. If your input contains these features, the parser will return an explicit error rather than producing incorrect output. For full YAML 1.2 compliance, use a dedicated library like PyYAML or js-yaml in your build pipeline.
How Block Parsing Works
YAML relies on indentation to determine structure. The parser tracks the number of leading spaces on each line to establish nesting levels. When a line has more indentation than the current block level, it becomes a child of the previous key or list item. When it returns to a previous indentation level, the current block closes.
For example, consider this snippet:
| Line | Indent | Parsed As |
|---|---|---|
server: | 0 | Mapping key at root |
host: localhost | 2 | Child mapping key |
port: 8080 | 2 | Child mapping key |
The parser sees that lines 2 and 3 are indented further than line 1, so they become values nested under the server key. The result is a JSON object where server maps to another object containing host and port.
Scalar Resolution Rules
Plain (unquoted) scalars follow specific resolution rules to match expected data types. It follows the YAML 1.2 core schema: true, false (also True/TRUE and so on) are booleans, null, ~ and empty values are null, and integers (decimal, 0x hex, 0o octal) and floats (including exponents) become numbers. Words such as yes, no, on and off stay strings, unlike YAML 1.1 parsers such as PyYAML, and dates stay strings. Integers beyond 2^53 are kept as strings so no digits are lost, and .inf/.nan produce an error because JSON cannot represent them. Duplicate keys are rejected.
Quoted scalars always remain strings. Double-quoted strings support escape sequences such as \n for newline, \t for tab, and \\ for a literal backslash. Single-quoted strings treat backslashes as literal characters and use doubled single quotes ('') to represent a single quote within the string.
Block Scalars Explained
Literal block scalars (indicated by |) preserve newlines exactly as written. Each line break within the indented block becomes a newline character in the resulting string. Folded block scalars (indicated by >) replace single line breaks with spaces, making them useful for long paragraphs that need to wrap in source files but render as continuous text.
Both styles support chomping indicators. A minus sign (-) strips the trailing newline, while a plus sign (+) keeps all trailing newlines. Without an indicator, the default behavior is to clip: keep exactly one trailing newline. An optional integer after the indicator specifies the base indentation level explicitly.
Common Errors and Edge Cases
Tabs in indentation cause errors because YAML requires spaces. A value that continues on the next line must be indented further than its key, and text such as a: b: c is rejected because a second colon inside a plain value is ambiguous. Another common issue is forgetting the space after a colon in a mapping; key:value is treated as a plain scalar string, not a key-value pair.
If you need to validate your YAML syntax before parsing, try the yaml validator. To format or clean up existing YAML, the yaml formatter can help standardize indentation. For checking style issues, use yaml lint. When converting between formats, tools like yaml to json conversions happen naturally here, but if you need to go the other direction or convert to xml to yaml, explore the related format tools.
Worked examples
| Example | Input | Result |
|---|---|---|
| Simple mapping | YAML input: name: Alice / age: 30 / active: true | { / "name": "Alice", / "age": 30, / "active": true / } |
| Nested sequence | YAML input: fruits: / - apple / - banana / - cherry | { / "fruits": [ / "apple", / "banana", / "cherry" / ] / } |
| Flow collection | YAML input: point: {x: 1, y: 2} / tags: [a, b, c] | { / "point": { / "x": 1, / "y": 2 / }, / "tags": [ / "a", / "b", / "c" / ] / } |
FAQ
What parts of YAML does this parser support?
It supports block mappings, block sequences, flow collections (brackets and braces), plain and quoted scalars, literal and folded block scalars, and comments. It follows the YAML 1.2 core schema for resolving booleans, nulls, and numbers.
Are anchors and aliases supported?
No. Anchors, aliases, tags, and merge keys are not supported. If the parser encounters them, it returns an explicit error message instead of producing incorrect output.
Is my YAML data sent to a server?
No. The yaml parser runs entirely in your browser using JavaScript. Your data never leaves your device and is never uploaded anywhere.
Why is my number being parsed as a string?
If a value is wrapped in quotes, it is always treated as a string. Integers larger than 9007199254740991 are also kept as strings so that no digits are lost, and values such as 1_000, 1:30 or 2020-01-01 are plain strings under YAML 1.2.
Can I parse multiple YAML documents at once?
No. Multi-document streams separated by triple dashes are not supported. Paste a single document at a time.
How does this compare to PyYAML safe_load?
For the supported subset, collections, quoted strings, block scalars and comments are read the same way as PyYAML safe_load. The scalar rules follow YAML 1.2, so PyYAML (YAML 1.1) differs for yes/no/on/off, which stay strings here, for numbers such as 1e3 and 0o17, which are numbers here, and for dates, which stay strings here. Unsupported features give an error instead of being processed.