Skip to content
ToolPlankDEV
JSON Tools
100% In-Browser Execution

Updated:

JSON to YAML Converter

Paste JSON and get YAML as you type. This json to yaml converter shows the line and column of any JSON error, can quote values that older YAML parsers misread, and lets you choose indent, quotes and key order. Nothing is uploaded.

Options:

JSON

Input
0 chars · 0 lines

YAML

Ready
Processing in browser...
0 chars · 0 linesUpdates as you type

Notes

Warnings about numbers, comments and documents appear here when there are any.

Processed on your device. Your text is not sent to our servers.

More free tools you may need next.

Quick Guide

How to use JSON to YAML

Simple step-by-step instructions to get the exact output you need.

  1. 01

    Paste your JSON

    Paste it into the left box, press Paste, or open a .json file. Example loads a small Kubernetes ConfigMap so you can see how values like yes and 1:30 are treated.

  2. 02

    Check the YAML as you type

    The YAML appears on the right at once. If the JSON has a mistake, the message names the line and column and tells you what to fix, for example a trailing comma or single quotes.

  3. 03

    Choose the style

    Pick 2 or 4 spaces, how text values are quoted, whether to also quote values that YAML 1.1 parsers misread, sorted keys, wrapped long lines, and whether a top-level array becomes several documents.

  4. 04

    Copy or download

    Press Copy to use the YAML, or Download to save it as a .yaml file.

How to convert JSON to YAML

JSON and YAML describe the same kinds of data: objects, lists, text, numbers, true or false, and null. To convert json to yaml, the tool reads your JSON, checks it, and writes the same data with YAML's indentation instead of braces, brackets and quotes.

The built-in example is a Kubernetes ConfigMap in one line of JSON. Converted with the default options, it gives:

yaml
apiVersion: v1
kind: ConfigMap
metadata:
  name: app-config
  labels:
    app: web
data:
  LOG_LEVEL: info
  ENABLE_CACHE: yes
  PORT_MAP: 80:80
  TIMEOUT: 1:30
  VERSION: "1.10"
  NOTES: |-
    line one
    line two

The status line reports 13 keys, 3 levels deep and 15 lines. Multi-line text becomes a block with a pipe, and VERSION keeps its quotes because an unquoted 1.10 would be read as the number 1.1.

Convert JSON to YAML online without breaking values

Look again at the output above. ENABLE_CACHE: yes and TIMEOUT: 1:30 are plain text in YAML 1.2, the current version, so they are correct. Many tools still read YAML 1.1, though. PyYAML, which Ansible uses, is one of them. These parsers turn yes, no, on and off into true and false, and read 1:30 as a time in seconds, so a value meant as text changes type.

Set Compatibility to Also safe for YAML 1.1 and those values are quoted:

yaml
  ENABLE_CACHE: "yes"
  PORT_MAP: 80:80
  TIMEOUT: "1:30"
  VERSION: "1.10"

The result reads back as the same text in both versions. This is the option to use when you are not sure which parser will read the file. It also quotes dates such as 2020-01-01, and the words y, n, on, off, true, false and null, because some parsers turn them into other types.

JSON to YAML options explained

  • Indent: 2 or 4 spaces for each nested level. Lists inside objects are indented under their key.
  • Text values: quote only when YAML needs it, or always use double or single quotes. Keys are never forced into quotes.
  • Compatibility: YAML 1.2 only, or also safe for YAML 1.1.
  • Sort keys: puts the keys of every object in alphabetical order, which makes two files easier to compare.
  • Wrap long lines: folds long text at 80 characters. Off by default, so each value stays on one line.
  • Allow comments and trailing commas: reads JSON written by hand, such as a tsconfig or a VS Code settings file, by removing // and /* */ comments and a comma before a closing bracket first.
  • Split a top-level array into documents: writes each item as its own document, separated by ---. Useful for turning a list of Kubernetes objects into one multi-document file.

JSON errors with line and column

Most JSON problems come from habits learned in other languages. The tool names the exact spot and gives a hint:

  • A comma before a closing bracket or brace, such as {"a":1,}, is not allowed.
  • Single quotes around text or keys are not allowed. JSON needs double quotes.
  • Keys must be in double quotes. {a:1} is JavaScript, not JSON.
  • Comments are not part of JSON. Turn on Allow comments and trailing commas if your file has them.
  • undefined, NaN and Infinity do not exist in JSON. Use null or a number.
  • Several JSON values in a row, as in a log file, need to be wrapped in a list.

JSON to YAML in Python and on the command line

For one file on your own machine, a command line tool works. With the yq tool installed:

Bash
yq -P config.json > config.yaml

In Python, with PyYAML installed:

Python
import json, yaml

with open('config.json') as f:
    data = json.load(f)
print(yaml.safe_dump(data, sort_keys=False, allow_unicode=True))

The page does the same job without installing anything, and shows the result as you edit. To go the other way, use YAML to JSON. For a config format that allows comments and has no indentation rules, JSON to TOML does the same job. If your JSON is stored as an escaped string inside another file, JSON Unescape turns it back into plain JSON first, and JSON Escape does the reverse. For files with one JSON object per line, JSONL Viewer helps you read them.

Limits

  • JSON has no comments, so YAML comments cannot be created. Comments in your JSON are dropped when you turn on the lenient option.
  • Whole numbers longer than 15 digits are rounded when JSON is read. The tool warns when it sees one.
  • Keys that look like whole numbers, such as 10 or 2, are moved to the front in numeric order. That comes from how JavaScript stores object keys, so it affects any tool built on JavaScript objects.
  • If the same key appears twice in one object, the last value wins.
  • The tool does not create anchors or aliases. Repeated data is written out in full each time.

Your JSON is converted in your browser. It is not uploaded or stored. See the Privacy Policy for details.

Frequently Asked Questions

Technical Q&A for JSON to YAML

Common questions about edge cases, character encoding, and privacy guarantees.

Paste your JSON into the left box. The YAML appears on the right at once. Press Copy or Download to use it.

Load the file with json.load and write it with yaml.safe_dump(data, sort_keys=False), using the PyYAML package. This page gives the same result without installing anything.

Mostly. YAML 1.2 was designed so that valid JSON is also valid YAML, but some older parsers differ on details such as tabs and long numbers. Converting writes cleaner, easier to read YAML.

YAML quotes text that would otherwise be read as a number, a boolean, null or a date, such as "1.10" or "null". Choose Also safe for YAML 1.1 to quote even more values, like yes and 1:30.

Yes, it writes standard YAML that those tools read. Use the Also safe for YAML 1.1 option so values such as yes, no and 1:30 are quoted and cannot be misread.

With yq installed, run yq -P config.json > config.yaml. Without any tool, paste the file contents into this page instead.

Yes. Turn on Allow comments and trailing commas. The comments are removed before conversion, because YAML output cannot carry them over from JSON.

The message gives the line and column and a hint. The usual causes are a trailing comma, single quotes, an unquoted key or a missing bracket.

Yes. Turn on Split a top-level array into documents and each item is written as its own document, separated by ---.

No. The conversion runs in your browser and nothing is sent to a server.