FormatterHQ

JSON to YAML Converter

Turn JSON into clean, block-style YAML for configs, manifests and docs. Ambiguous strings are quoted automatically so the YAML parses back to the same data.

Input JSON
Output YAML
Ready.

How to use the JSON to YAML Converter

  1. Paste JSON into the input editor, upload a .json file, use Load URL, or click Sample.
  2. Choose an Indent of 2 or 4 spaces and tick Sort keys if you want alphabetical order.
  3. Click Convert to YAML.
  4. Copy the YAML or Download it as a .yaml file.

Convert JSON to YAML that reads like hand-written config

Many tools accept both JSON and YAML, but people usually maintain the YAML version: it has less punctuation, supports comments and diffs well. This JSON to YAML converter takes any valid JSON and writes it in YAML block style, which is the style you see in Kubernetes manifests, GitHub Actions workflows and Docker Compose files.

Example

[
  {"id": 1, "name": "Ava", "tags": ["a", "b"]},
  {"id": 2, "name": "Noah", "tags": []}
]

With a 2-space indent the result is:

- id: 1
  name: Ava
  tags:
    - a
    - b
- id: 2
  name: Noah
  tags: []

Objects become mappings, arrays become sequences with - items, and an empty array is written in flow style as [] because it has no items to list.

Safe quoting: why some strings get quotes

YAML decides a value's type from how it looks. A JSON string that happens to look like a number, boolean, date or null must be quoted in YAML, or it would come back as a different type. The converter handles this automatically:

{"a":"yes","b":"123","c":"","e":"key: v","f":"#x","g":null,"i":"2024-05-01"}
a: 'yes'
b: '123'
c: ''
e: 'key: v'
f: '#x'
g: null
i: '2024-05-01'

Real null stays unquoted, while the string "123" keeps its quotes. Strings that start with # or contain : are quoted so they are not read as comments or mappings.

Options

  • Indent – 2 spaces (most common) or 4 spaces. With 4 spaces, list items are written as - id: 1, keeping item content aligned with the nested keys.
  • Sort keys – sorts object keys alphabetically at every level. Useful for canonical files and stable diffs; leave it off to keep the order of the original JSON.

How special values are written

  • Multi-line strings become literal block scalars, so "multi\nline" is written as |- followed by two indented lines, which is much easier to read than an escaped string.
  • Long strings are never wrapped, so URLs and base64 values stay on one line.
  • Repeated objects are written out in full; the converter does not create anchors and aliases.

What changes visually

The converted file drops JSON's braces, brackets, commas and most quotes. Structure is carried by indentation alone, so a nested object three levels deep is simply indented three steps. That is why YAML files are shorter and easier to scan, and also why indentation errors matter so much when you edit them later. If you plan to hand-edit the result, the YAML validator will catch a misplaced indent before a deployment tool does.

When to convert JSON to YAML

  • Turning an API response or a kubectl get -o json output into a manifest you can edit and commit.
  • Migrating a JSON config file to YAML so you can add comments.
  • Producing readable fixtures or examples for documentation.

If the JSON fails to parse, fix it first with the JSON fixer. The reverse direction is covered by the YAML to JSON converter, and for TOML-based tools there is JSON to TOML.

Privacy

The conversion runs in your browser; your JSON is not uploaded. Only Load URL (fetched through our server) and Save & Share (stored for the link) involve the server.

Convert JSON to YAML in Python

Parse the JSON with the built-in json module and write it with PyYAML's yaml.safe_dump. By default PyYAML sorts keys alphabetically, so the YAML no longer follows the order of your JSON; pass sort_keys=False to keep it. Add allow_unicode=True as well, otherwise a value like café is written as "caf\xE9".

# pip install pyyaml
import json

import yaml

data = '{"name": "café", "ports": [80, 443], "db": {"host": "localhost", "ssl": true}}'
obj = json.loads(data)

text = yaml.safe_dump(obj, sort_keys=False, allow_unicode=True)
print(text)

To confirm the structure your script should produce, paste the same JSON into the converter above; the YAML validator checks the file you end up with.

Frequently asked questions

Is JSON valid YAML?
Almost always, yes. YAML 1.2 was designed so that JSON documents are valid YAML, which is why many tools accept both. Converting to block style simply makes the file easier for people to read and edit.
Why are some of my strings wrapped in single quotes?
They would otherwise be read as another type, for example "yes", "123" or "2024-05-01". Quoting keeps them as strings when the YAML is parsed again.
Can I add comments after converting?
Yes. Add # comments anywhere in the YAML output. That is one of the main reasons to keep configuration in YAML rather than JSON.
Does the converter keep key order?
Yes, unless you tick Sort keys. Keys appear in the same order as in the JSON input.

Last updated October 3, 2026

Guides

Related tools

YAML to JSON Converter Convert YAML to JSON online for free. Get formatted JSON with types detected automatically. Base64 to YAML Decode a Base64 string back to YAML with syntax highlighting. CSV to YAML Converter Convert CSV to YAML online for free. Clean, readable YAML with configurable indentation. .env to YAML Converter Convert .env files to YAML for Docker Compose, Kubernetes or CI configs, optionally nesting keys on a separator. HTML Table to YAML Converter Convert HTML to YAML online for free. Clean, readable YAML with configurable indentation. Properties to YAML Converter Convert Spring Boot application.properties to application.yml, nesting dotted keys into a clean YAML tree. OPML to JSON Converter Convert OPML to JSON online for free. Get formatted JSON with types detected automatically. PDF to JPG Converter Convert PDF pages to JPG images (or PNG and WebP) at 72–300 DPI. Download single pages or all pages as a ZIP. Runs in your browser. PDF to Text Converter Extract all the text from a PDF, page by page, as plain text you can copy or download as .txt. Choose pages; works in your browser. Properties to JSON Converter Convert Java .properties files (Spring Boot, i18n bundles) to nested or flat JSON, decoding \uXXXX escapes and line continuations. Query String to JSON Parse URL query strings into JSON, including repeated keys, PHP/Rails bracket arrays (a[]=1) and nested objects (a[b][c]=1). RSS to JSON Converter Convert RSS to JSON online for free. Get formatted JSON with types detected automatically.