Developer and Text Tools

How to Convert YAML to JSON and JSON to YAML (With Examples)

Understand the differences between YAML and JSON, convert data both ways, avoid common indentation errors and know what is lost in conversion.

Saizul Amin
Saizul Amin১০ অক্টো, ২০২৬ · 3 মিনিটের পড়া
How to Convert YAML to JSON and JSON to YAML (With Examples)

YAML and JSON describe the same kind of data, but they look very different. JSON is strict and favoured by APIs, while YAML is easier for people to read and write and is common in configuration files such as Docker Compose and Kubernetes. Converting between them is a daily task for developers. The free YAML to JSON Converter does it in your browser.

Quick answer

Paste your YAML or JSON, choose the direction and copy the result. The tool validates the input and reports an error if it is not valid.

The YAML to JSON converter on shobfree.com with YAML input and JSON output The YAML to JSON Converter showing a configuration in both formats.

The same data in both formats

YAML:

name: shobfree
version: 2
tools:
  - pdf
  - image
settings:
  private: true

JSON:

{
  "name": "shobfree",
  "version": 2,
  "tools": ["pdf", "image"],
  "settings": { "private": true }
}

Key differences

FeatureYAMLJSON
ReadabilityVery readable, uses indentationNeeds braces and quotes
CommentsSupported with #Not supported
Quotes on stringsUsually optionalRequired
Trailing commasNot applicableNot allowed
Data typesStrings, numbers, booleans, null, datesStrings, numbers, booleans, null
Typical useConfiguration, CI pipelinesAPIs, data exchange

Common YAML mistakes

  1. Tabs for indentation. YAML allows only spaces. A tab causes a parse error.
  2. Inconsistent indentation. Child items must be indented more than the parent, and consistently.
  3. Unquoted special values. The words yes, no, on and off can be read as booleans, and a value like 1.10 becomes the number 1.1. Quote them when you mean text.
  4. A colon inside a value. Quote the string if it contains ": ".

Common JSON mistakes

  • Single quotes instead of double quotes.
  • A trailing comma after the last item.
  • Unquoted keys.
  • Comments, which JSON does not allow.

What is lost in conversion

Converting YAML to JSON drops comments and anchors, because JSON has no way to store them. YAML anchors and aliases are expanded into repeated data. Converting back produces clean YAML, but the original comments and ordering style are gone, so keep the original file if the comments matter.

When to use which

  • Use YAML for files that people edit often, with comments that explain choices.
  • Use JSON for data between programs, in APIs and in browsers, where strict, fast parsing matters.
  • Use the converter to check what a program will really read, when a YAML file behaves unexpectedly.

Format and validate JSON with the JSON Formatter, convert tables with the CSV to JSON tool or turn JSON into XML with the JSON to XML Converter.

Frequently asked questions

Is my data uploaded? No. The conversion runs entirely in your browser.

Is YAML a superset of JSON? Mostly. Valid JSON is almost always valid YAML 1.2, which is why the converter accepts JSON as YAML too.

Why did my number change? YAML reads some unquoted text as numbers. Quote the value to keep it a string.

Next step

Convert a file with the YAML to JSON Converter.

সম্পূর্ণ ফ্রিকোনো খরচ বা সাইন-আপ নেই
ফাইল নিরাপদকাজ শেষে স্বয়ংক্রিয় মুছে ফেলা
বাংলায় সহজবাংলা ও ইংরেজি দুই ভাষায়