Examples
This section provides practical examples of using the JSON to YAML Converter for various use cases.
Basic Examples
Simple Object Conversion
Input JSON:
{
"name": "John Doe",
"age": 30,
"email": "john@example.com",
"active": true
}
Output YAML:
name: John Doe
age: 30
email: john@example.com
active: true
Array Conversion
Input JSON:
{
"fruits": ["apple", "banana", "orange"],
"numbers": [1, 2, 3, 4, 5]
}
Output YAML:
fruits:
- apple
- banana
- orange
numbers:
- 1
- 2
- 3
- 4
- 5
Nested Object Conversion
Input JSON:
{
"user": {
"profile": {
"name": "Alice",
"age": 25,
"address": {
"street": "123 Main St",
"city": "New York",
"zip": "10001"
}
},
"preferences": {
"theme": "dark",
"notifications": true
}
}
}
Output YAML:
user:
profile:
name: Alice
age: 25
address:
street: 123 Main St
city: New York
zip: 10001
preferences:
theme: dark
notifications: true
Configuration File Examples
Application Configuration
Input JSON:
{
"app": {
"name": "MyApp",
"version": "1.0.0",
"debug": false,
"database": {
"host": "localhost",
"port": 5432,
"name": "myapp_db",
"ssl": true
},
"cache": {
"enabled": true,
"ttl": 3600,
"maxSize": "100MB"
}
}
}
Output YAML:
app:
name: MyApp
version: 1.0.0
debug: false
database:
host: localhost
port: 5432
name: myapp_db
ssl: true
cache:
enabled: true
ttl: 3600
maxSize: 100MB
Docker Compose Configuration
Input JSON:
{
"version": "3.8",
"services": {
"web": {
"build": ".",
"ports": ["3000:3000"],
"environment": {
"NODE_ENV": "production",
"DATABASE_URL": "postgresql://user:pass@db:5432/mydb"
},
"depends_on": ["db"]
},
"db": {
"image": "postgres:13",
"environment": {
"POSTGRES_DB": "mydb",
"POSTGRES_USER": "user",
"POSTGRES_PASSWORD": "pass"
},
"volumes": ["postgres_data:/var/lib/postgresql/data"]
}
},
"volumes": {
"postgres_data": {}
}
}
Output YAML:
version: 3.8
services:
web:
build: .
ports:
- 3000:3000
environment:
NODE_ENV: production
DATABASE_URL: postgresql://user:pass@db:5432/mydb
depends_on:
- db
db:
image: postgres:13
environment:
POSTGRES_DB: mydb
POSTGRES_USER: user
POSTGRES_PASSWORD: pass
volumes:
- postgres_data:/var/lib/postgresql/data
volumes:
postgres_data: {}
API Response Examples
REST API Response
Input JSON:
{
"status": "success",
"data": {
"users": [
{
"id": 1,
"name": "John Doe",
"email": "john@example.com",
"created_at": "2023-01-15T10:30:00Z",
"profile": {
"avatar": "https://example.com/avatar1.jpg",
"bio": "Software developer"
}
},
{
"id": 2,
"name": "Jane Smith",
"email": "jane@example.com",
"created_at": "2023-01-16T14:45:00Z",
"profile": {
"avatar": "https://example.com/avatar2.jpg",
"bio": "Designer"
}
}
],
"pagination": {
"page": 1,
"limit": 10,
"total": 2,
"pages": 1
}
}
}
Output YAML:
status: success
data:
users:
- id: 1
name: John Doe
email: john@example.com
created_at: 2023-01-15T10:30:00Z
profile:
avatar: https://example.com/avatar1.jpg
bio: Software developer
- id: 2
name: Jane Smith
email: jane@example.com
created_at: 2023-01-16T14:45:00Z
profile:
avatar: https://example.com/avatar2.jpg
bio: Designer
pagination:
page: 1
limit: 10
total: 2
pages: 1
CI/CD Pipeline Examples
GitHub Actions Workflow
Input JSON:
{
"name": "CI/CD Pipeline",
"on": {
"push": {
"branches": ["main"]
},
"pull_request": {
"branches": ["main"]
}
},
"jobs": {
"test": {
"runs-on": "ubuntu-latest",
"steps": [
{
"name": "Checkout",
"uses": "actions/checkout@v3"
},
{
"name": "Setup Node.js",
"uses": "actions/setup-node@v3",
"with": {
"node-version": "18"
}
},
{
"name": "Install dependencies",
"run": "npm install"
},
{
"name": "Run tests",
"run": "npm test"
}
]
}
}
}
Output YAML:
name: CI/CD Pipeline
on:
push:
branches:
- main
pull_request:
branches:
- main
jobs:
test:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Setup Node.js
uses: actions/setup-node@v3
with:
node-version: 18
- name: Install dependencies
run: npm install
- name: Run tests
run: npm test
Kubernetes Configuration Examples
Deployment Configuration
Input JSON:
{
"apiVersion": "apps/v1",
"kind": "Deployment",
"metadata": {
"name": "my-app",
"labels": {
"app": "my-app",
"version": "v1.0.0"
}
},
"spec": {
"replicas": 3,
"selector": {
"matchLabels": {
"app": "my-app"
}
},
"template": {
"metadata": {
"labels": {
"app": "my-app"
}
},
"spec": {
"containers": [
{
"name": "my-app",
"image": "my-app:1.0.0",
"ports": [
{
"containerPort": 3000
}
],
"env": [
{
"name": "NODE_ENV",
"value": "production"
}
]
}
]
}
}
}
}
Output YAML:
apiVersion: apps/v1
kind: Deployment
metadata:
name: my-app
labels:
app: my-app
version: v1.0.0
spec:
replicas: 3
selector:
matchLabels:
app: my-app
template:
metadata:
labels:
app: my-app
spec:
containers:
- name: my-app
image: my-app:1.0.0
ports:
- containerPort: 3000
env:
- name: NODE_ENV
value: production
Data Processing Examples
Log Data Conversion
Input JSON:
{
"logs": [
{
"timestamp": "2023-01-15T10:30:00Z",
"level": "INFO",
"message": "User login successful",
"user_id": 123,
"ip": "192.168.1.100"
},
{
"timestamp": "2023-01-15T10:31:00Z",
"level": "ERROR",
"message": "Database connection failed",
"error_code": "DB_CONN_001",
"retry_count": 3
}
]
}
Output YAML:
logs:
- timestamp: 2023-01-15T10:30:00Z
level: INFO
message: User login successful
user_id: 123
ip: 192.168.1.100
- timestamp: 2023-01-15T10:31:00Z
level: ERROR
message: Database connection failed
error_code: DB_CONN_001
retry_count: 3
Best Practices Examples
Well-Structured JSON
Input JSON:
{
"project": {
"name": "My Project",
"version": "1.0.0",
"description": "A sample project",
"author": {
"name": "John Doe",
"email": "john@example.com"
},
"dependencies": {
"production": {
"express": "^4.18.0",
"mongoose": "^6.0.0"
},
"development": {
"jest": "^29.0.0",
"eslint": "^8.0.0"
}
},
"scripts": {
"start": "node server.js",
"test": "jest",
"lint": "eslint ."
}
}
}
Output YAML:
project:
name: My Project
version: 1.0.0
description: A sample project
author:
name: John Doe
email: john@example.com
dependencies:
production:
express: ^4.18.0
mongoose: ^6.0.0
development:
jest: ^29.0.0
eslint: ^8.0.0
scripts:
start: node server.js
test: jest
lint: eslint .
Common Use Cases
Environment Configuration
- Convert JSON environment files to YAML
- Maintain configuration structure
- Improve readability for DevOps teams
API Documentation
- Transform JSON API schemas to YAML
- Create readable API documentation
- Maintain data structure integrity
Data Migration
- Convert JSON datasets to YAML format
- Maintain data accuracy and structure
- Facilitate data processing workflows
Configuration Management
- Convert application configurations
- Maintain consistency across environments
- Improve configuration readability
Tips for Better Results
- Validate JSON First: Ensure your JSON is valid before conversion
- Use Consistent Formatting: Well-formatted JSON produces cleaner YAML
- Review Output: Always check the converted YAML for accuracy
- Test with Examples: Use the provided examples to understand the conversion process
- Save Important Conversions: Use the download feature for important files