JSON ↔ YAML Converter
Convert JSON to YAML or YAML to JSON instantly.
2sp · UTF-8
Example Conversion
JSON:
json
{
"apiVersion": "v1",
"kind": "Service",
"metadata": { "name": "my-service" },
"spec": {
"ports": [{ "port": 80, "targetPort": 8080 }]
}
}YAML:
yaml
apiVersion: v1
kind: Service
metadata:
name: my-service
spec:
ports:
- port: 80
targetPort: 8080JSON vs YAML Syntax
| JSON | YAML |
|---|---|
| { "key": "value" } | key: value |
| ["a", "b", "c"] | - a - b - c |
| "string" | string (quotes optional) |
| true / false | true / false (or yes/no) |
| null | null or ~ |
| // not supported | # this is a comment |
Common Use Cases
- ▸Kubernetes manifests — Convert JSON API responses to YAML configs for kubectl apply
- ▸Docker Compose — Create docker-compose.yml from JSON templates
- ▸CI/CD pipelines — GitHub Actions, GitLab CI and CircleCI all use YAML configs
- ▸Ansible playbooks — Convert JSON data to YAML format for Ansible automation
- ▸Helm charts — Generate values.yaml files from JSON configuration
Special Characters in YAML
The converter automatically quotes strings that could be misinterpreted by YAML parsers:
• Strings starting with numbers:
"123abc"• Strings containing colons:
"host:port"• Boolean-like strings:
"yes", "no", "true"• Strings with special chars:
"#", "&", "*"Programmatic Conversion
JavaScript (Node.js):
js
const yaml = require('js-yaml');
const jsonData = { name: 'example', count: 42 };
const yamlString = yaml.dump(jsonData);
console.log(yamlString);Python:
python
import json, yaml
with open('data.json') as f:
data = json.load(f)
with open('data.yaml', 'w') as f:
yaml.dump(data, f, default_flow_style=False)