Skip to content

JSON to YAML and YAML to JSON

Convert between JSON and YAML in your browser. Edit either pane and the other updates live. Errors show inline so you can fix them as you type.

JSON and YAML are the same shape with different syntax

JSON and YAML both hold the same data shape: mappings, sequences and scalars. JSON wraps everything in punctuation (braces, brackets, commas, quotes), which makes it clear and easy to generate from code. YAML drops the punctuation and uses indentation instead, which makes it easier to read but easier to get wrong when written by hand.

Many tools accept both because both parse to the same structure in memory. Kubernetes manifests, GitHub Actions workflows and CloudFormation templates are usually written in YAML, but the engines behind them work with the parsed objects.

When to use this tool

  • Editing by hand a config you fetched as JSON. The API returned JSON and you would rather edit YAML. Convert, edit, convert back, and paste it into the request.
  • Reading dense JSON. A deeply nested JSON object is hard to read. Convert it to YAML and the indentation shows the structure clearly.
  • Writing a Helm or Kubernetes config from an API response. Many cluster APIs return JSON but accept YAML. This conversion gets your output into the right format.

Worked examples

  • Strings that look like numbers. YAML version: "1.0" stays a string in JSON: "version": "1.0". Drop the quotes in YAML (version: 1.0) and JSON becomes "version": 1. Quoting matters.
  • Booleans. YAML 1.2 accepts true / false only. Older parsers also accept yes / no / on / off; js-yaml does not. If you have old YAML that uses those, quote them.
  • Null. YAML ~ or an empty value becomes JSON null. In the other direction, JSON null becomes YAML null.

Common mistakes

  • Tabs in YAML. YAML does not allow tabs for indentation. If your YAML mixes tabs and spaces, the parser rejects it. This tool shows the parse error inline.
  • Spaces around the colon. name : value (space before the colon) is valid. name: value needs no space before the colon and at least one after it.
  • Multi-line strings. YAML block scalars (| and >) keep or fold newlines. JSON has no such style; multi-line content becomes a string with \n characters in it.
  • Comments are lost. JSON has no comment syntax, so a YAML to JSON to YAML round trip removes every comment you wrote in YAML. There is no way around this.
  • Anchors and aliases. YAML &name and *name let you reuse a part of the tree. When we write YAML from JSON, we write the full structure with no anchors. That is fine for most uses.

FAQ

Does this tool support YAML anchors and aliases?

YAML to JSON: yes, anchors and aliases are resolved. JSON to YAML: no anchors are written, because JSON has no idea of references.

Why are my YAML strings sometimes quoted?

js-yaml quotes strings that would otherwise be unclear (numbers, booleans, and special words like "yes", "no", "null"). This is correct YAML; without the quotes a parser would read them as something else.

Can I convert YAML 1.1 specifics like sexagesimal numbers?

js-yaml follows YAML 1.2 by default, which dropped sexagesimal numbers and the "yes/no" booleans. Most modern YAML follows 1.2.

How are comments handled?

YAML comments are removed during parsing because JSON has no comment syntax. There is no way to keep them through this tool.

Why does my round trip lose key ordering?

JavaScript keeps JSON object keys in insertion order, and js-yaml keeps that order on output too. If you see a change, it is likely because the YAML input had its keys in a different order than the JSON.