Helm JSON to YAML Conversion

Helm accepts both JSON and YAML for values files. Convert with yq -o=json values.yaml or use --set-json for inline JSON. Helm templates must be YAML, but values can be either format. This guide covers Helm JSON to YAML conversion, working with values files, and best practices.

Helm Values Files: JSON vs YAML

Helm charts use values.yaml for default configuration. You can override values using either YAML or JSON files.

values.yaml Example

# Default values for myapp
replicaCount: 3

image:
  repository: nginx
  tag: "1.24"
  pullPolicy: IfNotPresent

service:
  type: ClusterIP
  port: 80

resources:
  limits:
    cpu: 100m
    memory: 128Mi
  requests:
    cpu: 50m
    memory: 64Mi

Same Values in JSON

{
  "replicaCount": 3,
  "image": {
    "repository": "nginx",
    "tag": "1.24",
    "pullPolicy": "IfNotPresent"
  },
  "service": {
    "type": "ClusterIP",
    "port": 80
  },
  "resources": {
    "limits": {
      "cpu": "100m",
      "memory": "128Mi"
    },
    "requests": {
      "cpu": "50m",
      "memory": "64Mi"
    }
  }
}
Key difference: YAML allows comments (#) which are useful for documenting configuration options. JSON values files work but lack documentation. See our YAML vs JSON comparison for more details.

Convert values.yaml to JSON

Use these methods to convert Helm values from YAML to JSON:

Method 1: yq

# Convert values.yaml to JSON
yq -o=json values.yaml > values.json

# Pretty print with indentation
yq -o=json -P values.yaml > values.json

# Convert and pipe to jq for further processing
yq -o=json values.yaml | jq '.image'

Method 2: helm get values

# Export current release values as JSON
helm get values myrelease -o json > current-values.json

# Get all values (including defaults)
helm get values myrelease -a -o json > all-values.json

# Get specific release in namespace
helm get values myrelease -n production -o json

Method 3: Python

import yaml
import json

with open('values.yaml') as f:
    values = yaml.safe_load(f)

with open('values.json', 'w') as f:
    json.dump(values, f, indent=2)

Convert JSON to values.yaml

Method 1: yq

# Convert JSON to YAML
yq -P values.json > values.yaml

# Add header comment
echo "# Generated from values.json" > values.yaml
yq -P values.json >> values.yaml

Method 2: Online Converter

Use our free online converter to instantly convert JSON values to YAML format.

Using --set-json Flag

Helm 3.10+ supports --set-json for passing JSON values inline:

# Set a JSON object inline
helm install myapp ./chart --set-json 'image={"repository":"nginx","tag":"1.24"}'

# Set array values
helm install myapp ./chart --set-json 'tolerations=[{"key":"node","operator":"Exists"}]'

# Combine with regular --set
helm install myapp ./chart \
  --set replicaCount=3 \
  --set-json 'resources={"limits":{"cpu":"100m"}}'

# Use with upgrade
helm upgrade myapp ./chart --set-json 'config={"debug":true}'
Method Best For Example
--set Simple key=value --set image.tag=1.24
--set-json Complex objects/arrays --set-json 'config={"a":1}'
-f values.yaml Full config files -f production.yaml
-f values.json CI/CD automation -f generated.json

Best Practices

✅ When to Use YAML Values

  • Human-edited configs: Comments help documentation
  • Version control: Easier to review diffs
  • Base values: Default values.yaml in chart
  • Environment configs: staging.yaml, production.yaml

✅ When to Use JSON Values

  • CI/CD pipelines: Programmatically generated
  • API integrations: Output from scripts
  • Dynamic values: Built by automation tools
  • jq processing: Complex value manipulation
Pro tip: Keep base configuration in YAML for readability, use JSON for dynamically generated overrides in CI/CD.

Frequently Asked Questions

Can Helm use JSON instead of YAML?

Yes, Helm accepts JSON for values files. You can use helm install -f values.json or pass JSON inline with --set-json. However, Helm templates must be YAML. Most teams use YAML for values because it's more readable and supports comments.

How do I convert Helm values.yaml to JSON?

Use yq to convert: yq -o=json values.yaml > values.json. You can also use helm get values myrelease -o json to export current release values as JSON for scripting and automation purposes.

Why does Helm use YAML?

Helm uses YAML because Kubernetes uses YAML for manifests. YAML supports comments for documentation, is more readable than JSON, and allows multi-document files with --- separators. This makes Helm charts easier to maintain and customize.

How do I pass JSON values to Helm?

Use --set-json for inline JSON: helm install myapp ./chart --set-json 'config={"key":"value"}'. For JSON files, use -f: helm install myapp ./chart -f values.json. Both methods work for install, upgrade, and template commands.

Need to convert JSON to YAML?

Use our free online converter—perfect for Helm values files.

Open Converter Tool →