JSON to YAML Converter

Paste JSON and click Convert to YAML. You get indented YAML that keeps your key order, with quotes only where they are needed. XML works too.

Editor (Formatted View)
1
Ready — paste or type JSON or XML here
Viewer
Converted output will appear here
Ready

How to convert JSON to YAML

  1. Paste your JSON, open a .json file, or click Load Sample.
  2. Click Convert to YAML. If the JSON has a syntax error, the line is highlighted, and Repair can fix common mistakes such as trailing commas.
  3. Copy the YAML or download it as a .yaml file.

Example

{
  "service": "orders",
  "replicas": 3,
  "env": { "LOG_LEVEL": "info", "REGION": "no" },
  "ports": [8080, 9090],
  "motd": "Welcome\nRead the docs first"
}

becomes

service: orders
replicas: 3
env:
  LOG_LEVEL: info
  REGION: "no"
ports:
- 8080
- 9090
motd: |-
  Welcome
  Read the docs first

Objects become indented blocks, arrays become - lists, and a string with line breaks becomes a |- block that's easy to read and edit. Key order stays the same as in your JSON.

Why some values get quotes

Quotes are added only where leaving them out would change the meaning when the YAML is read back:

Real numbers, booleans and null from the JSON are written without quotes.

Kubernetes, OpenAPI and CI files

Most tools accept JSON, but people read YAML. Converting is handy when you:

Since YAML 1.2 is a superset of JSON, the conversion never loses data. Going back with the YAML to JSON converter gives you the same JSON.

Converting JSON to YAML in code

# Python (pip install pyyaml)
import json, yaml
print(yaml.safe_dump(json.load(open('data.json')), sort_keys=False))

// Node.js (npm install js-yaml)
const yaml = require('js-yaml');
console.log(yaml.dump(JSON.parse(fs.readFileSync('data.json', 'utf8'))));

# Command line with yq
yq -P data.json

Pass sort_keys=False in Python, otherwise PyYAML sorts the keys alphabetically.

Frequently asked questions

Is JSON valid YAML?

Yes. YAML 1.2 is a superset of JSON, so a JSON file is already valid YAML. Converting simply rewrites it in the indented YAML style, which is easier to read and edit.

Does the converter keep the order of keys?

Yes. Keys appear in the YAML in the same order as in the JSON.

Why does "no" get quotes in the YAML?

Many YAML parsers read an unquoted no, yes, on or off as a boolean. The quotes make sure the value stays the text you had in the JSON.

Can I convert XML to YAML?

Yes. Paste XML instead of JSON and click Convert to YAML. Attributes and repeated elements are converted the same way as in the XML to JSON tool.

Is my JSON stored?

No. It is sent to our server only to be converted and is not saved. The YAML comes straight back to your browser.

Other tools

Share Content

Choose what to share and generate an instant link

🔥 One-time link Content deleted from server after first view
✉️
Uploading to server…