How to Convert JSON to YAML (and Back)

March 22, 2026 · 5 min read

JSON and YAML are two of the most popular data serialization formats. If you work with configuration files, APIs, or DevOps tools, you'll inevitably need to convert between them.

In this guide, you'll learn the key differences between JSON and YAML, when to use each, and how to convert between them — with examples and a free online converter.

JSON vs YAML: Key Differences

FeatureJSONYAML
SyntaxBraces and bracketsIndentation-based
CommentsNot supportedSupported (#)
ReadabilityGood for machinesGreat for humans
Data typesStrings, numbers, booleans, null, arrays, objectsSame + dates, timestamps, multi-line strings
Common useAPIs, package.json, tsconfigDocker Compose, Kubernetes, Ansible, CI/CD
StrictnessVery strict (quotes required)More flexible (quotes optional)

The Same Data in JSON and YAML

JSON

{ "name": "my-app", "version": "1.0.0", "dependencies": { "express": "^4.18.0", "lodash": "^4.17.21" }, "scripts": { "start": "node index.js", "test": "jest" }, "production": true, "ports": [3000, 8080] }

YAML

name: my-app version: 1.0.0 dependencies: express: ^4.18.0 lodash: ^4.17.21 scripts: start: node index.js test: jest production: true ports: - 3000 - 8080

The YAML version is shorter and arguably easier to scan. This is why YAML is the go-to format for configuration files like docker-compose.yml, .github/workflows/*.yml, and Kubernetes manifests.

How to Convert JSON to YAML

Method 1: Online Converter (Instant)

The fastest way — paste your JSON and get YAML instantly:

Convert JSON to YAML

Paste JSON, get clean YAML. Runs in your browser — nothing leaves your device.

Open JSON to YAML Converter

Method 2: Command Line with Python

# Install PyYAML if needed pip install pyyaml # Convert a file python -c "import json, yaml, sys; print(yaml.dump(json.load(sys.stdin), default_flow_style=False))" < config.json > config.yaml

Method 3: Command Line with yq

# Install yq (https://github.com/mikefarah/yq) # macOS: brew install yq # Linux: snap install yq # Convert JSON to YAML yq -P config.json > config.yaml # Convert YAML to JSON yq -o=json config.yaml > config.json

Method 4: In Node.js

const fs = require('fs'); const yaml = require('js-yaml'); // npm install js-yaml // JSON to YAML const jsonData = JSON.parse(fs.readFileSync('config.json', 'utf8')); const yamlStr = yaml.dump(jsonData); fs.writeFileSync('config.yaml', yamlStr); // YAML to JSON const yamlData = yaml.load(fs.readFileSync('config.yaml', 'utf8')); const jsonStr = JSON.stringify(yamlData, null, 2); fs.writeFileSync('config.json', jsonStr);

How to Convert YAML to JSON

Going the other direction? Use the YAML to JSON converter or the command-line methods above in reverse.

Convert YAML to JSON

Paste YAML, get formatted JSON.

Open YAML to JSON Converter

Common Gotchas

When to Use Which

Related Tools