JSON in DevOps: Automation, Configuration, and Pipeline Integration
JSON is the lingua franca of DevOps. From infrastructure-as-code templates to CI/CD pipeline configurations, monitoring dashboards to container orchestration, JSON powers the tooling that modern operations teams rely on. This guide covers JSON usage in Docker, Kubernetes, Terraform, Ansible, CI/CD pipelines, and monitoring systems. Use our JSON Validator to check manifests and JSON Formatter to format configurations.
JSON in Infrastructure as Code (IaC)
| Tool | Format | Common Files | JSON Usage |
|---|---|---|---|
| Docker | JSON | docker-compose.json | Service definitions, networks, volumes |
| Kubernetes | JSON / YAML | deployment.json, service.json | Resource manifests (Pod, Service, Deployment) |
| Terraform | HCL / JSON | terraform.tfstate.json | State files, plan outputs, variables |
| Ansible | YAML / JSON | inventory.json, facts.json | Inventory, gathered facts, output |
| AWS CloudFormation | JSON / YAML | template.json | Resource definitions, parameters |
Kubernetes Resource Manifests in JSON
// Kubernetes Deployment in JSON
{
"apiVersion": "apps/v1",
"kind": "Deployment",
"metadata": {
"name": "web-app",
"labels": { "app": "web", "env": "production" }
},
"spec": {
"replicas": 3,
"selector": {
"matchLabels": { "app": "web" }
},
"template": {
"metadata": {
"labels": { "app": "web" }
},
"spec": {
"containers": [{
"name": "app",
"image": "myapp:v1.2.3",
"ports": [{ "containerPort": 8080 }],
"env": [
{ "name": "NODE_ENV", "value": "production" },
{ "name": "DB_URL", "valueFrom": {
"secretKeyRef": {
"name": "db-secret",
"key": "url"
}
}}
],
"resources": {
"requests": { "cpu": "100m", "memory": "128Mi" },
"limits": { "cpu": "500m", "memory": "512Mi" }
}
}]
}
}
}
}
// Apply with kubectl
// kubectl apply -f deployment.json
Docker Compose in JSON
{
"version": "3.8",
"services": {
"api": {
"image": "node:18",
"ports": ["3000:3000"],
"environment": {
"NODE_ENV": "development",
"DB_HOST": "database"
},
"volumes": ["./app:/app"],
"depends_on": ["database"]
},
"database": {
"image": "postgres:15",
"environment": {
"POSTGRES_DB": "myapp",
"POSTGRES_PASSWORD": "devpassword"
},
"volumes": ["pgdata:/var/lib/postgresql/data"]
}
},
"volumes": {
"pgdata": {}
}
}
Terraform State in JSON
Terraform stores infrastructure state as JSON. Understanding the state file format is critical for debugging:
// terraform.tfstate.json (simplified)
{
"version": 4,
"terraform_version": "1.5.0",
"serial": 42,
"resources": [
{
"module": "root",
"mode": "managed",
"type": "aws_instance",
"name": "web_server",
"provider": "provider["registry.terraform.io/hashicorp/aws"]",
"instances": [
{
"schema_version": 1,
"attributes": {
"id": "i-0abcd1234efgh5678",
"instance_type": "t3.medium",
"ami": "ami-0c55b159cbfafe1f0",
"tags": {
"Name": "web-server-prod",
"Environment": "production"
}
}
}
]
}
]
}
// Query state with jq
// jq '.resources[] | select(.type == "aws_instance") | .instances[].attributes.id' terraform.tfstate.json
CI/CD Pipeline JSON
JSON is commonly used in CI/CD pipelines for artifacts, metadata, and build outputs:
// GitHub Actions workflow artifact
{
"name": "build-output",
"files": ["dist/app.js", "dist/app.css"],
"metadata": {
"buildNumber": 1234,
"commitSha": "abc123def456",
"branch": "main",
"timestamp": "2025-01-15T10:30:00Z"
}
}
// Jenkins pipeline parameters as JSON
{
"parameter": [
{ "name": "BRANCH", "value": "main" },
{ "name": "ENVIRONMENT", "value": "staging" }
]
}
Monitoring and Alerting
// Prometheus alert rule in JSON
{
"groups": [{
"name": "production-alerts",
"rules": [{
"alert": "HighCPULoad",
"expr": "node_load1 > 2.0",
"for": "5m",
"labels": { "severity": "critical" },
"annotations": {
"summary": "CPU load is high",
"description": "CPU load on {{ $labels.instance }} is {{ $value }}"
}
}]
}]
}
// Datadog monitor definition
{
"name": "High Error Rate Monitor",
"type": "metric alert",
"query": "avg(last_5m):avg:http.requests.errors{*} > 10",
"message": "Error rate exceeded 10 per minute",
"tags": ["service:api", "env:production"]
}
CI/CD Pipeline Validation
Use our JSON Validator to check Kubernetes manifests, Docker compose files, and other DevOps JSON files before applying them. Use JSON Schema Validator to validate against official schemas. Format deployment files with JSON Formatter before committing.
DevOps JSON Best Practices
- Always validate Kubernetes manifests with JSON Validator before applying
- Use JSON Schema validation for Terraform variable files
- Format JSON consistently (2-space indent) across all DevOps files
- Store secrets in Kubernetes Secrets or Vault, never in JSON config files
- Use jq for command-line JSON processing in CI/CD scripts
- Monitor JSON log outputs with structured logging parsers
- Use JSON Minifier for production artifacts to reduce size
Next Steps
Validate your Kubernetes manifests with JSON Validator. Format deployment files with JSON Formatter. Validate against schemas with JSON Schema Validator. Minify production artifacts with JSON Minifier.