Tutorial · 5 min read

How to Convert Kubernetes YAML to JSON Online

Working with Kubernetes manifests in YAML is standard, but CI/CD pipelines, automation scripts, and some tools require JSON format. Use a Kubernetes YAML to JSON converter to transform manifests — Deployments, Services, ConfigMaps, Ingress — without installing anything.

1. Basic K8s Manifest Conversion

A single Kubernetes manifest — like a Deployment or Service — converts cleanly from YAML to JSON:

apiVersion: apps/v1 kind: Deployment metadata: name: nginx-deployment spec: replicas: 3 selector: matchLabels: app: nginx

Paste this into the converter and it becomes valid JSON with the same structure. The converter preserves all fields, including nested objects and arrays like containers, ports, and volumes.

This is the most common use case — taking a single kubectl get output or a hand-written manifest and converting it for use in a script or API call.

2. Multi-Document YAML with ---

Kubernetes often uses multi-document YAML files where resources are separated by ---. This is common in Helm charts and production manifests:

apiVersion: v1 kind: Namespace metadata: name: production --- apiVersion: apps/v1 kind: Deployment metadata: name: api-server namespace: production spec: replicas: 5

A good converter splits each document at the --- boundary and converts them individually. The output can be a JSON array of resources or separate JSON objects, making it easy to iterate over them in scripts.

The converter on JSONXX handles this automatically — no manual splitting required.

3. Anchors and Aliases

YAML anchors (&name) and aliases (*name) reduce duplication in Kubernetes manifests:

x-labels: &default-labels app: myapp env: staging apiVersion: v1 kind: Service metadata: name: my-service labels: *default-labels

The converter must resolve anchors and aliases before converting to JSON, because JSON has no equivalent concept. The *default-labels reference is expanded inline with the actual label values.

Without anchor resolution, the resulting JSON would be invalid. Always use a converter that supports this.

4. Validation After Conversion

After converting YAML to JSON, always validate the result. Common issues include:

Use the JSON validator to check your output before feeding it into kubectl or a CI/CD pipeline.

5. Converting for CI/CD Pipelines

CI/CD pipelines often prefer JSON for programmatic manipulation. Here are common scenarios:

The browser-based converter fits perfectly into this workflow — no need to install yq or python-yaml on your CI runner.

Convert Your K8s Manifests Now

Paste your Kubernetes YAML, get clean JSON. Supports multi-document files, anchors, and aliases.

Convert YAML to JSON Now →

Frequently Asked Questions

How do I convert Kubernetes YAML to JSON with kubectl?

Use kubectl get deployment my-deploy -o json to get JSON directly. For local files, use kubectl apply --dry-run=client -f manifest.yaml -o json.

Can multi-resource YAML files be converted?

Yes. A converter supporting the --- separator splits and converts each resource independently. The output handles each document separately.

Is the JSON output compatible with kubectl apply?

Yes. Kubernetes accepts both YAML and JSON formats natively. Use kubectl apply -f manifest.json — the API treats them identically.

Is there any data loss when converting YAML to JSON?

Minimal. Anchors/aliases are resolved to their values. YAML comments are discarded (JSON doesn't support them). YAML-specific types like timestamps may need adjustment.

How does performance scale for large clusters?

Browser-based conversion handles manifests up to 50MB. For production clusters with hundreds of resources, consider converting individual files or using kubectl native JSON output.

Looking for more guides? See the full JSONXX How To index.