G
Great Online Apps
JSON to YAML Converter: Convert Both Ways Online

JSON to YAML Converter: Convert Both Ways Online

Convert JSON to YAML and YAML to JSON instantly. See how the formats map, which YAML values change type, and how to avoid errors with our free converter.

To convert JSON to YAML, drop the braces, brackets and quotes and express the structure with indentation instead: each object key becomes key: value on its own line, nested objects are indented by two spaces, and array items become lines that start with - . Converting YAML to JSON reverses the process.

Our free JSON to YAML converter does this in both directions as you type. This guide shows how the two formats map onto each other, the YAML type rules that silently change your data, and how to convert config files without surprises.

JSON vs YAML: the key differences

JSON (RFC 8259) is strict and compact, which makes it the default for APIs. YAML is designed for people to read and edit, which is why tools such as Kubernetes, Docker Compose, GitHub Actions and OpenAPI use it for configuration. YAML 1.2 was revised to make JSON an official subset, so a valid JSON document is, in practice, also valid YAML.

JSON YAML
Structure Braces {} and brackets [] Indentation with spaces
Strings Always in double quotes Quotes usually optional
Comments Not allowed Allowed with #
Reuse None Anchors &, aliases * and merge keys
Multi-line text \n escapes Block scalars | and >
Typical use APIs, data exchange Configuration files

Example: converting JSON to YAML

Here is a small service config in JSON:

{"name":"checkout-api","port":8080,"debug":false,"hosts":["api.example.com","api-eu.example.com"],"database":{"driver":"mysql","pool":10}}

The converter produces this YAML:

name: checkout-api
port: 8080
debug: false
hosts:
  - api.example.com
  - api-eu.example.com
database:
  driver: mysql
  pool: 10

Every JSON object became a block of indented keys, and the hosts array became a list of - items. Paste the YAML back in with the direction set to YAML to JSON and you get the same data as pretty-printed JSON.

How multi-line strings convert

A JSON string containing \n line breaks, such as "line1\nline2", is written as a YAML literal block. The | keeps line breaks, and the - after it drops the final newline:

message: |-
  line1
  line2

YAML gotchas when converting to JSON

YAML guesses the type of unquoted values. That is convenient until a value you meant as text turns into a number or a boolean. These results come from our converter, which follows YAML 1.2 rules:

YAML input JSON output Why
version: 1.10 "version": 1.1 Read as a number, so the trailing zero is lost
version: "1.10" "version": "1.10" Quotes keep it a string
enabled: yes "enabled": "yes" Only true/false are booleans in YAML 1.2
timeout: "timeout": null An empty value is null, as is ~
mode: 0o14 "mode": 12 0o marks an octal number

Older YAML 1.1 parsers, still common in some languages, treat yes, no, on and off as booleans. That is the source of the well-known "Norway problem", where the country code NO becomes false. Quote these values, version numbers and dates such as "2025-01-15" so every parser reads them as text.

Anchors, aliases and merge keys

JSON has no way to reference other values, so the converter expands YAML anchors into full copies:

base: &base
  retries: 3
prod:
  <<: *base
  region: eu

becomes {"base": {"retries": 3}, "prod": {"retries": 3, "region": "eu"}} in JSON. Comments are dropped in the same way, because JSON cannot store them.

How to use the JSON / YAML Converter

  1. Open the JSON / YAML converter and choose JSON to YAML or YAML to JSON.
  2. Paste your document into the input box, up to 100,000 characters. The output updates automatically as you type.
  3. Read the result: YAML output uses 2-space indentation and quotes strings that would otherwise be read as another type, such as 'yes' or '01234'. JSON output is pretty-printed with 4-space indentation.
  4. If the input is invalid, you see a message such as "Invalid JSON: Syntax error" or "Invalid YAML" with the line number and the text near the problem.
  5. Click Copy to copy the output, or Clear to start over.

Tips for clean conversions

  • Indent YAML with spaces, never tabs. The YAML spec forbids tabs for indentation, and the converter reports "A YAML file cannot contain tabs as indentation" with the line number.
  • Convert one document at a time. Files that hold several documents separated by ---, common in Kubernetes manifests, must be split first.
  • Validate JSON first. The JSON formatter shows the exact line and column of a syntax error and can remove comments and trailing commas for you.
  • Compare before and after. When you hand-edit a converted config, paste both versions into the text diff viewer to confirm only the intended lines changed.
  • Remember that Kubernetes Secrets are only encoded. Their values are Base64, not encrypted. Decode one with the Base64 converter and you see the plain value, as explained in our guide to Base64 encoding.
  • Strip secrets before pasting. The converter processes input on our server. Replace passwords, tokens and keys with placeholders before converting a production config.

For the JSON side of the format, our guide on how to format and validate JSON covers every syntax rule.

Frequently asked questions

How do I convert JSON to YAML?

Paste the JSON into a converter set to JSON to YAML, or rewrite it by hand: remove braces and quotes, put each key on its own line as key: value, indent nested objects by two spaces, and prefix array items with - .

Is YAML a superset of JSON?

Yes, for practical purposes. YAML 1.2 was revised so that JSON is an official subset, which means most YAML 1.2 parsers can read a JSON document directly.

Can YAML have comments?

Yes. Anything after a # on a line is a comment in YAML. JSON has no comments, so they are lost when you convert YAML to JSON.

Why did my YAML value change type after conversion?

Unquoted YAML values are interpreted by type, so 1.10 becomes the number 1.1 and an empty value becomes null. Wrap a value in quotes to keep it a string.

Can I use tabs in YAML?

No. The YAML specification allows only spaces for indentation. A tab at the start of a line causes a parse error.

Should I use JSON or YAML for configuration?

YAML is easier to read and supports comments, which makes it popular for hand-edited config. JSON is stricter and has fewer type surprises, which makes it safer for machine-generated files and data exchange.

Ready to use this tool?

Try the JSON / YAML Converter now and simplify your workflow immediately.

G
Great Online Apps
Toggle sidebar