YAML to JSON Converter
Convert YAML configurations and structures into readable JSON format.
YAML to JSON
Turn common block YAML into readable JSON
This YAML to JSON converter reads a practical subset of indentation-based YAML and serializes the result as valid, pretty-printed JSON. It understands nested mappings, dash lists, lists of simple objects, quoted and unquoted scalars, common boolean spellings, null literals, numbers, and comments outside quoted text. Output can use two or four spaces, then be copied or downloaded as converted.json.
The parser is self-contained rather than a complete YAML implementation. That keeps the workflow immediate, but advanced YAML constructs and some malformed input are not diagnosed the way a standards-compliant parser would diagnose them. Use the page for conventional configuration-shaped documents and verify critical conversions against the application’s real YAML library.
Conversion workflow
- Paste YAML into YAML Input.
- Choose 2 Spaces or 4 Spaces under JSON Indentation. Two spaces is the initial setting.
- Read the generated JSON Output. It refreshes on every source or indentation change.
- Correct any error shown beside the input.
- Select Copy or Download after output appears. Clear empties both panels and removes the error.
The indentation choice affects JSON presentation only. It does not change how YAML nesting is recognized. YAML nesting comes from the leading whitespace in the source.
Supported mapping and sequence shapes
A line containing key: value becomes an object property. A key with nothing after its colon receives a nested block when the following nonblank line is more indented. If there is no nested block, that property becomes null.
A line beginning with - starts or continues an array at that indentation. Plain list values become scalars. An empty dash can contain a nested map or list below it. A list item written as - name: worker begins an object, and additional key-value lines at the item’s nested indentation are added to that same object.
Example:
application:
name: courier
ports:
- 8080
- 8081
workers:
- name: mailer
enabled: true
retries: 3
- name: cleanup
enabled: false
retries: 1
With two-space JSON indentation, the result is:
{
"application": {
"name": "courier",
"ports": [
8080,
8081
],
"workers": [
{
"name": "mailer",
"enabled": true,
"retries": 3
},
{
"name": "cleanup",
"enabled": false,
"retries": 1
}
]
}
}
Root mappings and root dash lists are both supported. Blank lines are ignored. The parser uses the indentation count it finds rather than requiring exactly two spaces, although consistent indentation is still necessary for correct grouping.
Scalar conversion rules
Double-quoted and single-quoted values become strings with their surrounding quotes removed. The parser performs limited unescaping for a matching escaped quote. It is not a full implementation of YAML escape sequences or multiline folding.
Unquoted scalar values are interpreted in this order:
true,yes, andonbecome JSONtrue;false,no, andoffbecome JSONfalse;nulland~become JSONnull;- any value accepted by JavaScript
Number(...)becomes a number; - everything else remains a string.
These choices resemble common YAML 1.1 behavior for boolean words. A system using YAML 1.2 may treat some of them differently. Quote yes, no, on, and off when they must remain strings.
Numeric conversion uses JavaScript rules rather than the complete YAML numeric grammar. Large integers can lose precision, and strings such as 0012 become the number 12 unless quoted. Date-like text is not specially parsed and generally remains a string.
How comments are handled
For every line, the parser scans for # outside single or double quotes and removes the rest of the line. Full-line comments disappear, and inline comments after a value are ignored:
host: api.example.com # public endpoint
token_hint: "prefix#suffix"
The quoted hash remains part of token_hint. Quote tracking is lightweight and checks whether a quote is immediately preceded by a backslash. Complex escape sequences may not behave exactly like a full YAML tokenizer.
Comments are not represented in JSON because JSON has no comment syntax. Once converted, they cannot be recovered from the output or download.
Formats that need another parser
Flow-style collections are not parsed structurally. Values such as [one, two] and {enabled: true} remain strings rather than becoming arrays or objects. The code specifically avoids treating braces and brackets as list-item mappings, but it does not implement their internal grammar.
Block scalars (| and >), anchors, aliases, merge keys, explicit tags, directives, document markers, multiple documents, complex keys, sets, binary values, and timestamp resolution are unsupported. Tabs do not receive special YAML indentation validation. Quoted strings do not implement the full escape and folding rules.
Lines in a mapping block that contain no colon can be skipped rather than producing a clear error. Some inconsistent indentation can also end a block early and omit later content instead of reporting invalid YAML. Therefore, the presence of JSON output is not proof that every source line was understood.
Useful conversion scenarios
Inspect a small configuration as typed data
JSON makes inferred booleans, numbers, nulls, arrays, and objects explicit. Convert a conventional service config to check how this parser interprets scalar values. Compare those types with the runtime’s YAML parser before changing production behavior.
Prepare a JSON fixture
Copy a mapping or list from a simple YAML example, choose the repository’s preferred indentation, and download. Review the diff before committing because comments disappear and scalar spellings can change type.
Move data into a JSON-only API
For a basic block document, conversion creates a request-shaped JSON value. Confirm that unsupported YAML features are absent and validate the result against the API contract.
Debug indentation
If a nested value appears at the wrong JSON level, inspect its leading spaces relative to sibling lines. The side-by-side panels make structural mistakes easier to recognize than a parser error alone.
Troubleshooting unexpected JSON
A word became a boolean
Quote it in YAML. yes, no, on, and off are coerced by this parser, as are true and false.
Leading zeros disappeared
The unquoted scalar passed numeric conversion. Write "0012" when the digits represent an identifier rather than a number.
An inline list became a string
Rewrite it in block form:
features:
- search
- export
Flow collections are outside the supported subset.
Part of a value vanished after a hash
An unquoted # begins a comment. Quote the complete text if the hash belongs to the value.
Nested properties are missing or misplaced
Align sibling keys at exactly the same indentation and indent children farther than their parent. Avoid tabs and mixed indentation. Also ensure mapping lines contain a colon.
Four Spaces changes only appearance
That setting controls JSON.stringify output indentation. It cannot repair YAML nesting. Correct the source spacing in the left editor.
No output appears for blank or comment-only input
Blank input clears the result. A nonblank document reduced to no meaningful lines is represented as an empty object by the parser.
Information lost during conversion
JSON cannot preserve YAML comments, anchors, aliases, tags, stylistic quoting, mapping-key formatting, or block-scalar style. This converter also resolves its supported scalar spellings into JavaScript values before serialization. A JSON-to-YAML round trip will not recreate the original document.
Object property names always become JSON strings. Undefined values do not exist. Numbers use JavaScript’s numeric representation, imposing safe-integer and floating-point limits. Extremely large or deeply nested documents can strain browser memory or recursive parsing.
For deployment manifests and security-sensitive configuration, use the same mature YAML parser as the target platform and fail on every unsupported or malformed construct.
YAML to JSON FAQ
Can it convert a YAML list at the root?
Yes. A document beginning with dash items becomes a JSON array.
Are comments included in the JSON?
No. Hash comments outside quotes are removed before parsing.
Does it support lists of objects?
Yes, for common block syntax such as - name: main followed by indented sibling properties.
Does it support inline arrays and objects?
No. Bracketed and braced flow values are retained as strings rather than parsed as collections.
What indentation can the JSON use?
Choose two or four spaces. YAML input indentation is independent of that choice.
Which filename is downloaded?
The browser creates converted.json with an application/json media type.
Are YAML anchors and aliases resolved?
No. Anchors, aliases, and merge keys are unsupported.
Is output enough to prove valid YAML?
No. The subset parser may skip or simplify unsupported constructs. Validate important source with a standards-compliant YAML implementation.