YAML to JSON Converter

YAML Input
Settings
Options
JSON Output
Copied!

YAML is popular for configuration files, and JSON is the standard format for APIs and web apps. When you need to move data from one to the other, converting by hand is slow and easy to get wrong. The YAML to JSON Converter above turns YAML into valid JSON, shows clear errors with the line number, and runs in your browser. Your data is never uploaded.

Table of Contents

YAML vs JSON

Both formats store the same kinds of data: text, numbers, true or false, null, lists and key-value objects. They are written very differently.

Feature YAML JSON
Structure Indentation Braces and brackets
Comments Yes, with # No
Quotes around text Usually optional Always required
Multi-line text Built in (| and >) Only with \n escapes
Reuse with anchors Yes (& and *) No
Typical use Config files, CI/CD, Kubernetes APIs, web apps, data exchange

YAML 1.2 was designed so that JSON is valid YAML, which is why conversion in this direction is reliable. You can read the details in the YAML 1.2.2 specification and the JSON standard (RFC 8259).

How to Use the YAML to JSON Converter

  1. Add your YAML. Paste it into the input box, or click Open File to load a .yaml or .yml file. Click Try Sample to see an example.
  2. Choose your settings. Pick the JSON indentation and the options you need.
  3. Check the result. The JSON output updates as you type. If the YAML has a problem, a message shows the line number and the lines around it.
  4. Copy or download. Click Copy JSON or Download .json.

Settings Explained

  • JSON indentation. Choose 2 spaces, 4 spaces or a tab for readable output, or Minified for one compact line that is best for sending over a network.
  • Sort keys alphabetically. Sorts the keys inside every object. Leave it off to keep the same order as your YAML.
  • Read yes, no, on, off as booleans (YAML 1.1). Off by default. See the next sections for why this matters.

How YAML Values Become JSON

YAML JSON Note
count: 42 "count": 42 Numbers stay numbers.
zip: "02134" "zip": "02134" Quoted values stay text.
active: true "active": true true and false become booleans.
value: ~ or empty "value": null null, ~ and empty values become null.
date: 2024-01-15 "date": "2024-01-15" JSON has no date type, so dates stay text.
text: | with indented lines One string with \n Line breaks are kept.
Anchors and aliases Expanded copies JSON repeats the values. Merge keys (<<) are merged into the object.
Comments Removed JSON has no comments.
Several documents separated by --- A JSON list Each document becomes one item.
.inf or .nan null JSON cannot hold these numbers. The tool tells you.

Very large whole numbers, beyond the safe range of JavaScript, are written out with all their digits so no precision is lost.

YAML 1.1 vs 1.2: Why "on" and "yes" Matter

Older YAML parsers (YAML 1.1) read yes, no, on and off as booleans. YAML 1.2 only treats true and false that way. This tool follows YAML 1.2 by default, so on stays the text "on".

A well-known example is the on: key in GitHub Actions workflow files. A 1.1 parser turns that key into true, while a 1.2 parser keeps it as "on". If your data comes from a system that uses the older rules, tick the YAML 1.1 option.

Important! If your YAML contains values like yes, no, on or off and you want them to stay text, put them in quotes. Quoted values are text in every YAML version.

Common YAML Errors and How to Fix Them

Message Usual cause Fix
Tabs are not allowed for indentation A tab character was used to indent. Replace tabs with spaces.
Bad indentation of a mapping entry A key is indented more or less than its neighbors. Align keys at the same level.
Mapping values are not allowed here A line is indented under a plain value, or text contains a colon followed by a space. Fix the indentation or quote the text.
Unexpected ": " inside a plain value A value like title: Hello: World. Quote it: title: "Hello: World".
Unterminated quoted string A closing quote is missing. Add the closing quote.
Unknown alias An alias (*name) is used before its anchor (&name) or the anchor is missing. Define the anchor earlier in the file.

Limitations to Know

  • It covers the common YAML features. Block and flow collections, quoted text, multi-line text, anchors, aliases, merge keys and multiple documents work. Complex keys (starting with ?) are not supported.
  • Custom tags are ignored. The tool shows a note when it skips one. The tags !!str, !!int, !!float, !!bool and !!null are understood.
  • Comments are lost. JSON cannot store them, so keep your original YAML.
  • Duplicate keys. YAML says keys must be unique. The tool uses the last value and shows a note.
  • Special cases. For unusual YAML, check the result against an official library such as js-yaml or PyYAML.

Frequently Asked Questions

Is the YAML to JSON Converter free, and is my data uploaded?

It is free and needs no signup. The conversion runs in your browser, so your YAML stays on your device.

Why did my YAML comments disappear?

JSON does not support comments, so they cannot be kept. Save your original YAML file if you need the comments later.

Why is my value a string instead of a number or boolean?

Quoted values are always text. Also, values such as yes, on and dates like 2024-01-15 stay text under YAML 1.2. Tick the YAML 1.1 option if you want yes, no, on and off read as booleans.

What happens to a file with several documents?

Documents are separated by --- in YAML. The tool combines them into one JSON list, with one item per document.

Can it convert Kubernetes, Docker Compose or GitHub Actions files?

Yes, these use standard YAML, including lists, nested objects and multi-line text. Remember that the GitHub Actions on: key stays the text "on" unless you tick the YAML 1.1 option.

Does the order of keys change?

No. The keys keep the order of your YAML, even when a key is a number. Turn on Sort keys alphabetically only if you want them sorted.

Final Thoughts

Converting YAML to JSON should be quick and predictable. Paste your YAML, read the error message if one appears, quote any text that could be misread, and copy the result. Keep your original YAML file, because it holds the comments that JSON cannot.

Post a Comment