yamljson
JSON
YAML

Ready

Everything runs in your browser. Your file is never uploaded, logged or sent anywhere. How can I verify that?

JSON to YAML Converter

Paste JSON, get clean YAML. It runs entirely in your browser, keeps your keys in order, and quotes the values that would otherwise break in older YAML parsers.

Choices this converter makes for you

Converting JSON to YAML is not one obvious answer — there are several ways to write the same data, and the defaults chosen by most libraries are wrong for configuration files. Here is what this one does and why.

Long strings are never wrapped

Most YAML libraries fold lines at 80 characters by default, which splits long URLs and base64 secrets across multiple lines. That is the single most common complaint about converters in this category. This one never folds.

YAML 1.1 traps are quoted

The keys and values on, off, yes, no and anything shaped like 22:30 are quoted by default. Without that, a GitHub Actions workflow whose trigger is on: breaks for anyone reading it with a YAML 1.1 parser — which is still most of them.

Key order is preserved exactly

Keys come out in the order you wrote them, including numeric-looking keys such as "1" and "0" which JavaScript objects silently reorder. Sorting a Kubernetes manifest makes its diff unreviewable, so sorting is off unless you ask for it.

Multi-line strings become readable blocks

A string containing newlines is written as a literal block scalar using the | indicator, rather than a single line full of \n escapes. That is the whole reason to move to YAML.

A worked example

A GitHub Actions workflow, in both formats. This particular example is worth studying because it contains the single most common YAML trap there is.

JSON
{
  "name": "deploy",
  "on": { "push": { "branches": ["main"] } },
  "jobs": {
    "build": {
      "runs-on": "ubuntu-latest",
      "steps": [
        { "uses": "actions/checkout@v4" },
        { "run": "npm ci && npm test" }
      ]
    }
  }
}
YAML
name: deploy
"on":
  push:
    branches:
      - main
jobs:
  build:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - run: npm ci && npm test

Look at the second line: "on" is quoted. Under YAML 1.1 the bare word on is the boolean true, so an unquoted version of this file gives you a workflow whose trigger is a key called true — and GitHub silently never runs it. Most converters emit it unquoted. This one does not.

Why convert JSON to YAML at all?

JSON is the format APIs speak. YAML is the format configuration is written in — Kubernetes manifests, Docker Compose files, GitHub Actions workflows, Ansible playbooks, OpenAPI specifications. The usual reason to convert is that you have an API response, a generated file, or an example from documentation in JSON, and you need it as a config file a human will maintain.

YAML earns that role by being easier to read and edit: no braces, no quotes around most values, no trailing-comma errors, and it supports comments — which JSON does not, and which is often the single reason teams move a config file over.

Converting JSON to YAML in code

For anything scripted, do it in code. Note the options in each example — the defaults are usually not what you want.

Python
import json, yaml

with open("data.json") as f:
    data = json.load(f)

print(yaml.safe_dump(data, sort_keys=False, default_flow_style=False))
Node.js
import { readFileSync } from "node:fs"
import { stringify } from "yaml"

const data = JSON.parse(readFileSync("data.json", "utf8"))
console.log(stringify(data, { lineWidth: 0 }))
Command line (yq)
yq -P data.json

# or with jq installed
jq . data.json | yq -P
Go
import "sigs.k8s.io/yaml"

yamlBytes, err := yaml.JSONToYAML(jsonBytes)

In Python, sort_keys=False matters — PyYAML sorts keys alphabetically by default, which scrambles a manifest. In Node, lineWidth: 0 matters for the same reason described above.

Frequently asked questions

How do I convert a JSON file to YAML online?

Paste the JSON into the converter at the top of this page, or drag your .json file straight onto the editor. You can copy the YAML out or download it as a .yaml file. It needs no install, no sign-up and no extension, works on Windows, macOS and Linux alike, and the conversion happens in your browser rather than on a server.

How do I convert Swagger JSON to YAML?

A Swagger or OpenAPI file is ordinary JSON, so any correct JSON to YAML conversion works — paste it into the converter above. Two things matter for a spec in particular. Key order must be preserved, or the familiar swagger, info, paths sequence gets scrambled and the file becomes hard to review. And long strings such as $ref values and descriptions must not be wrapped across lines. This converter does both by default; many do neither.

How do I convert OpenAPI JSON to YAML?

The same way as any JSON: paste it into the converter above. OpenAPI 3 uses YAML and JSON interchangeably, so no restructuring is needed. Teams usually move to YAML so the spec can carry comments and be reviewed in pull requests without a wall of braces. Check afterwards that your $ref paths still resolve and that any version-like value, for example 3.10, is quoted — unquoted it is read as the number 3.1.

How do I convert JSON to YAML in Notepad++?

Notepad++ cannot do it on its own. Its JSON plugins format and validate JSON but do not convert between formats, and plain Windows Notepad certainly cannot. Your practical options are a converter like this page, or the command line with yq -P data.json. If you do paste YAML back into Notepad++ afterwards, set the encoding to UTF-8 without BOM — a BOM is the cause of the "invalid leading UTF-8 octet" error that Kubernetes reports later.

How do I convert JSON to YAML in Java?

Use Jackson with the YAML data format module. Read the JSON with a plain ObjectMapper, then write it with an ObjectMapper backed by YAMLFactory: new ObjectMapper(new YAMLFactory()).writeValueAsString(obj). By default Jackson writes a leading --- document marker; disable YAMLGenerator.Feature.WRITE_DOC_START_MARKER if you do not want it. Add jackson-dataformat-yaml alongside jackson-databind.

How do I convert JSON to YAML in Python?

Load the JSON and dump it as YAML: import json, yaml — then data = json.load(open("data.json")) followed by print(yaml.safe_dump(data, sort_keys=False, default_flow_style=False)). The sort_keys=False part matters. PyYAML sorts keys alphabetically by default, which scrambles a Kubernetes manifest or an OpenAPI spec into something nobody can review.

How do I convert JSON to YAML in Linux, bash or the command line?

The usual tool is yq. With Mike Farah’s Go version, run yq -p=json -o=yaml data.json, or the shorter yq -P data.json. With the Python yq by Andrey Kislyuk, the equivalent is yq -y . data.json. The two share a name and nothing else, so run yq --version first if a command does not behave as documented. With neither installed, bash can fall back to Python: python3 -c "import json,yaml,sys; print(yaml.safe_dump(json.load(sys.stdin), sort_keys=False))" < data.json.

Can I use jq to convert JSON to YAML?

Not on its own. jq reads and writes JSON only — it has no YAML output mode, which is why jq . data.json still gives you JSON. What people usually mean is yq, and the Python yq by Andrey Kislyuk is literally a jq wrapper: it accepts the same filter syntax and yq -y . data.json emits YAML. So your jq expressions carry over unchanged; you just swap the command and add -y.

How do I convert JSON to YAML in VS Code (vscode)?

Visual Studio Code has no built-in JSON to YAML command. Two things work reliably. Install a vscode extension that adds a conversion command to the palette, or open the integrated terminal and run yq -P data.json, which needs nothing installed in the editor itself. For a one-off, pasting into the converter on this page is quicker than either.

How do I convert JSON to YAML in IntelliJ?

IntelliJ IDEA does not ship a one-click JSON to YAML action in the base IDE. Plugins from the JetBrains Marketplace add one, and the built-in terminal runs yq -P data.json without installing anything into the IDE. For a quick one-off, pasting into this page saves restarting IntelliJ for a plugin you will use once.

How do I convert JSON to YAML in JavaScript or Node.js?

Install the yaml package, then stringify the parsed JSON: import { stringify } from "yaml", followed by stringify(JSON.parse(text), { lineWidth: 0 }). The lineWidth: 0 part matters — without it the library folds lines at 80 characters and splits long URLs and tokens across multiple lines. The older js-yaml package uses dump() the same way, with lineWidth: -1 for the equivalent behaviour.

How do I convert JSON to YAML in Ansible?

Use the to_nice_yaml filter, which is built in — no collection required. To turn a JSON file into YAML: {{ lookup("file", "data.json") | from_json | to_nice_yaml }}. from_json parses the text and to_nice_yaml formats it with block style and indentation. Pass to_nice_yaml(indent=2) to match the two-space convention used by Kubernetes and most Ansible projects. The plain to_yaml filter also exists but emits harder-to-read flow style.

Why is my on: key breaking my GitHub Actions workflow?

Under YAML 1.1 the bare word on is read as the boolean true, so a workflow trigger can end up as a key named true instead of on — and GitHub simply never runs it. This converter quotes on, yes, no, off and time-like values by default, which keeps the output safe for the many parsers still following YAML 1.1. You can see it in the worked example on this page: the second line is "on", with quotes.

Why did my long URL get split across several lines?

Because most YAML libraries fold lines at 80 characters by default. That splits long URLs, base64 secrets and tokens across multiple lines, and while the YAML is still technically valid it is unreadable and easy to corrupt when edited by hand. This converter never folds — every string stays on one line. In Node, set lineWidth: 0; in Python, pass width=10**9 to safe_dump.

Does the conversion preserve the order of my keys?

Yes, exactly as written, including numeric-looking keys such as "1" and "0" that a plain JavaScript object silently reorders. This matters more than it sounds: reordering a Kubernetes manifest makes its diff unreviewable. Sorting is available but off unless you ask for it, which is the opposite of PyYAML’s default.

What can YAML do that JSON cannot?

Comments, which is often the entire reason a team moves a config file to YAML. Also anchors and aliases for reusing a block, multiple documents in one file separated by ---, multi-line strings written as readable blocks rather than one line full of \n escapes, and non-string keys. Converting from JSON never loses anything, because JSON is the smaller format — it is the return trip that has to drop things.

Is my data uploaded anywhere?

No. The conversion runs entirely in your browser using JavaScript downloaded with the page. Nothing is sent to a server, nothing is logged, and there is no account. You can confirm it yourself: open DevTools, switch to the Network tab, and convert something — you will see no requests. A Content Security Policy on the site blocks outbound requests entirely, so this is enforced by your browser rather than merely promised.