yaml to jsonyamljsonconfig filesdata formatsdevops

YAML to JSON Conversion: Everything You Need to Know

YAML and JSON represent the same data differently. Learn what makes them different, when to convert between them, and how to go from YAML to JSON instantly.

10 min read

Related Tool

YAML to JSON

Open tool

YAML and JSON are two of the most widely used data formats in software development. You will encounter them in configuration files, API responses, CI/CD pipelines, Kubernetes manifests, Docker Compose files, and countless other places. They represent exactly the same kinds of data but look completely different. This guide explains what each format is, why you would convert from one to the other, and how to do it instantly using a free browser-based tool.

What Is YAML?

YAML originally stood for Yet Another Markup Language, though the community later settled on the recursive acronym YAML Ain't Markup Language to emphasise that it is a data serialisation format rather than a document markup language.

YAML is designed to be human-friendly. It uses indentation to show structure rather than curly braces and square brackets. Strings usually do not need to be wrapped in quotes. Comments are supported, which is one of its biggest advantages over JSON for configuration files.

A YAML file that describes a server configuration might list the host name, port number, and a set of allowed origins, all using simple key-colon-value pairs. Arrays are written as indented lists preceded by a hyphen. Nested objects are shown by indenting their properties under the parent key.

YAML is used extensively in tools like Ansible, Kubernetes, GitHub Actions, Docker Compose, AWS CloudFormation, and many CI/CD systems.

What Is JSON?

JSON stands for JavaScript Object Notation. It is a text format that uses curly braces for objects, square brackets for arrays, colons to separate keys from values, and commas to separate items. All strings must be in double quotes. JSON does not support comments.

JSON is the dominant format for data exchange between web services and APIs. It is unambiguous, compact, and supported by every programming language. It is also the required format for many configuration inputs: npm package.json files, VS Code settings, schema definitions, and many REST API request bodies all require JSON.

How YAML and JSON Represent the Same Data

The two formats are semantically equivalent for most data types. Every valid JSON document is also valid YAML (YAML is a superset of JSON). However, valid YAML is not always valid JSON.

YAML supports features that JSON does not: comments, multi-line strings without escape sequences, anchors and aliases for reusing values, and multiple documents in a single file separated by three dashes. When converting YAML to JSON, these YAML-only features are either dropped (comments) or translated into their JSON equivalents.

Why Convert YAML to JSON?

There are several common scenarios where you need to go from YAML to JSON.

Working with APIs that expect JSON. You might keep configuration in a YAML file for readability, but a particular API endpoint only accepts JSON in the request body. Convert the YAML to JSON before sending.

Debugging Kubernetes or Docker configurations. Running a YAML manifest through a JSON converter lets you inspect the exact structure that the orchestration system will see. Some validation tools also work better with JSON input.

Feeding YAML config into a JSON Schema validator. JSON Schema is the standard way to validate data structure, but validators expect JSON input. Convert your YAML first and then validate the JSON.

Sharing data with tools that do not support YAML. Not every environment has a YAML parser available. JSON parsers are essentially universal.

Checking that your YAML is syntactically valid. If the converter produces clean JSON output, your YAML is valid. If it throws an error, you have a syntax problem in the YAML.

YAML Quirks to Know Before Converting

YAML has a few behaviours that sometimes cause surprises during conversion.

Booleans. In YAML, the bare words true, false, yes, no, on, and off are all interpreted as booleans. The values yes and no in particular can catch you off guard. When converted to JSON, they become the JSON boolean values true and false, not the strings "yes" and "no". If you intended them as strings, they need to be quoted in the YAML source.

Null values. In YAML, a tilde character alone or the word null or an empty value after a colon all represent null. JSON uses the word null.

Numbers. YAML parses unquoted numbers as integers or floats. A value like 1.0 becomes a JSON number. A value like 001 might be interpreted as an octal number in some YAML parsers. Quote numeric-looking values that are actually strings (like ID codes or version strings) to avoid surprises.

Multi-line strings. YAML supports block scalars (using a pipe character or a greater-than sign to introduce multi-line strings). The pipe character preserves line breaks. The greater-than sign folds line breaks into spaces. Both convert to a single JSON string with the appropriate formatting.

Anchors and aliases. YAML lets you define a value once with an anchor and reference it elsewhere with an alias. When converting to JSON, anchors are expanded so every reference gets the full value inlined. The resulting JSON file will be larger if anchors were used heavily.

How to Convert YAML to JSON Using DevHexLab

The DevHexLab YAML to JSON tool converts your YAML in the browser without sending the data to any server.

Open the tool at /tools/json/yaml-to-json. Paste your YAML content into the input panel on the left. The converted JSON appears in the right panel automatically. If your YAML has a syntax error, the tool highlights the problem so you can fix it. Click Copy to grab the JSON, or Download to save it as a .json file.

The tool handles all standard YAML features including nested objects, arrays, booleans, null values, quoted strings, and multi-line block scalars.

What About JSON to YAML?

The reverse conversion (JSON to YAML) is equally useful and follows the same logic in reverse. DevHexLab also has a JSON to YAML tool at /tools/json/json-to-yaml for when you need to go the other direction.

Frequently Asked Questions

Is YAML a superset of JSON?

Yes. All valid JSON is also valid YAML because YAML's syntax is a superset of JSON's. However, not all valid YAML can be directly represented as JSON, since YAML supports comments, anchors, and other features that JSON does not have.

Why does my YAML boolean become a number in JSON?

This usually happens when a value that looks like a boolean is being parsed unexpectedly. Check that booleans in your YAML are lowercase (true or false) and that values you intend as strings are quoted.

Can I convert a multi-document YAML file to JSON?

A YAML file with multiple documents separated by three dashes contains more than one root-level value. JSON does not support multiple root values in a single file. Most tools either convert the first document only or produce a JSON array containing all documents. The DevHexLab tool converts the first document by default.

Does YAML support comments?

Yes. YAML supports single-line comments starting with a hash character. JSON does not support comments at all. When converting YAML to JSON, all comments are discarded.

Which format should I use for configuration files?

Use YAML for human-edited configuration files where comments and readability matter. Use JSON for machine-generated configuration, API communication, and any context where a comment would cause a parse error.

Switch Between Formats in Seconds

YAML and JSON represent the same data in two different styles. Knowing how to move between them quickly makes you more flexible when working across different tools and platforms. Open the DevHexLab YAML to JSON converter, paste your configuration, and have valid JSON ready instantly.

Try it yourself with this free tool

YAML to JSON

Convert YAML configuration files to JSON