YAML ⇄ JSON
Convert between YAML and JSON, from text or a file.
About YAML ⇄ JSON
Convert YAML to JSON or JSON to YAML in the browser. Paste text or drop a file, the direction is detected from the input, and the result appears as you type.
How to use
- Paste YAML or JSON, or load a
.yaml,.ymlor.jsonfile (up to 5 MB) with the file picker or by dropping it on the page. - Input that parses as JSON is converted to YAML; anything else, including flow-style YAML such as
{a: 1}, is parsed as YAML and converted to JSON. Use the Auto / YAML → JSON / JSON → YAML switch to force a direction. - The output updates as you type. Copy it, or Download it as
.jsonor.yamlnamed after the loaded file.
What it supports
- Parsing and emitting are done by js-yaml. Loading uses the YAML 1.2 core schema: anchors and aliases are resolved,
2024-01-01stays a string,0o17is the integer 15, and custom tags are not executed. - A multi-document stream separated by
---becomes a JSON array with one item per document. - YAML → JSON output is indented with two spaces.
- JSON → YAML output is written with no line wrapping, so long strings stay on one line.
- A YAML parse error names the line and column.
- Comments in YAML are not carried into JSON, because JSON has no comment syntax.
Example
name: xutil
tools:
- jwt
- yaml
→
{
"name": "xutil",
"tools": [
"jwt",
"yaml"
]
}
Privacy
Conversion runs in the page. A dropped file is read locally, no request is made, and nothing is stored.
Frequently asked questions
- Is YAML a superset of JSON?
- Almost. YAML 1.2 was designed so that any valid JSON document is also valid YAML, which is why a JSON file can be fed straight to most YAML parsers. The reverse is not true: YAML adds comments, anchors, multi-line strings and unquoted keys that JSON cannot express.
- Why did my YAML value "no" or "on" turn into a boolean?
- The YAML 1.1 schema treats yes, no, on and off as booleans. js-yaml follows the stricter YAML 1.2 core schema, so only true and false are booleans; quote a value if you need it kept as a string either way.
- What happens to comments when I convert YAML to JSON?
- They are dropped. JSON has no comment syntax, so there is nowhere to put them; keep the original YAML if the comments matter.
- What happens to a multi-document YAML stream?
- Documents separated by a --- line are converted together into a JSON array, one item per document. A stream with a single document is converted to that document alone, not wrapped in an array.