https://github.com/philyuchkoff/dash2yaml
Bash script to convert Grafana JSON dashboards to YAML format for kube-prometheus-stack
https://github.com/philyuchkoff/dash2yaml
dashboards grafana grafana-dashboard json2yaml kube-prometheus-stack kubernetes kubernetes-deployments monitoring monitoring-automation observability tojson yaml-converter
Last synced: 12 days ago
JSON representation
Bash script to convert Grafana JSON dashboards to YAML format for kube-prometheus-stack
- Host: GitHub
- URL: https://github.com/philyuchkoff/dash2yaml
- Owner: philyuchkoff
- License: mit
- Created: 2026-05-25T07:08:24.000Z (27 days ago)
- Default Branch: main
- Last Pushed: 2026-05-25T07:29:53.000Z (27 days ago)
- Last Synced: 2026-05-25T09:23:33.619Z (27 days ago)
- Topics: dashboards, grafana, grafana-dashboard, json2yaml, kube-prometheus-stack, kubernetes, kubernetes-deployments, monitoring, monitoring-automation, observability, tojson, yaml-converter
- Language: Shell
- Homepage:
- Size: 16.6 KB
- Stars: 0
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# dashtoyaml
Bash script to convert Grafana JSON dashboards to YAML format for [kube-prometheus-stack](https://github.com/prometheus-community/helm-charts/tree/main/charts/kube-prometheus-stack).
## Features
- Convert Grafana JSON dashboards to YAML format
- Fix template variables from `[[var]]` to `$var` format
- Fix datasource references
- Add custom prefix/suffix to dashboard UID
- Specify folder for dashboards (added as comment)
- Custom datasource naming
- Force specific UID
- Optional YAML formatting via `yq`
## Requirements
- `jq` - JSON processor
- `python3` - for template variable fixes
- `yq` (optional) - for YAML formatting
### Installing Dependencies
```bash
# Ubuntu/Debian
sudo apt-get install jq python3
# macOS
brew install jq python3 yq
# CentOS/RHEL
sudo yum install jq python3
```
## Usage
### Basic
```bash
./dashtoyaml.sh dashboard.json dashboards/dashboard.yaml
```
### With prefix and suffix
```bash
./dashtoyaml.sh dashboard.json dashboards/dashboard.yaml \
--prefix prod_ \
--suffix _v1
```
### With folder specification
```bash
./dashtoyaml.sh dashboard.json dashboards/dashboard.yaml \
--folder "Production Dashboards"
```
### With custom datasource
```bash
./dashtoyaml.sh dashboard.json dashboards/dashboard.yaml \
--datasource "MyPrometheus"
```
### Full options
```bash
./dashtoyaml.sh dashboard.json dashboards/my.yaml \
--prefix stage_ \
--suffix _2024 \
--folder "Stage Dashboards" \
--datasource "Prometheus"
```
### Force specific UID
```bash
./dashtoyaml.sh dashboard.json dashboards/my.yaml \
--uid custom-uid
```
## Options
| Option | Description |
|--------|-------------|
| `--prefix TEXT` | Add prefix to dashboard UID |
| `--suffix TEXT` | Add suffix to dashboard UID |
| `--folder NAME` | Specify folder name (added as comment) |
| `--datasource NAME` | Datasource name (default: `Prometheus`) |
| `--uid NAME` | Force specific UID |
| `--help` | Show help message |
## Integration with kube-prometheus-stack
After conversion, deploy dashboards via ConfigMap:
```bash
kubectl create configmap grafana-dashboards \
--from-file=dashboards/ \
--dry-run=client \
-o yaml | kubectl apply -f -
```
Or use Helm values:
```yaml
grafana:
dashboards:
dashboard-provider:
folders:
- name: Production
path: /tmp/dashboards/production
- name: Stage
path: /tmp/dashboards/stage
dashboardProviders:
dashboardproviders.yaml:
apiVersion: 1
providers:
- name: 'default'
orgId: 1
folder: ''
type: file
disableDeletion: false
editable: true
options:
path: /var/lib/grafana/dashboards/default
```
## Example
Input JSON (`dashboard.json`):
```
{
"title": "Kubernetes Cluster Monitoring",
"uid": "cluster-monitoring",
"panels": [...],
"templating": {
"list": [...]
}
}
```
Output YAML (`dashboards/cluster.yaml`):
```
# cluster.yaml
# Automated generated from dashboard.json
# 2026-05-25 10:30:00
# Directory: Production Dashboards
# Datasource: Prometheus
title: Kubernetes Cluster Monitoring
uid: prod_cluster-monitoring_v1
version: 1
tags:
- kubernetes
- monitoring
panels:
- ...
templating:
list:
- ...
```
## License
MIT