Skip to main content

EXPORT A GRAFANA DASHBOARD TO A JSON FILE

This guide shows you how to save a dashboard that was built in the Grafana UI as a JSON file in your repository, so you can review it, version it, and push it again later.

Prerequisites

  • A behavior named grafana of type @keeb/grafana/instance, with grafanaUrl set to your Grafana server (see Create and Run a Behavior)
  • If your Grafana server needs an API key, the apiKey global argument referenced from a vault with ${{ vault.get('<vault-name>', '<key>') }} (see Vaults)

If the @keeb/grafana extension is not in the repository yet, pull it:

swamp extension pull @keeb/grafana

The output looks like:

INF extension·pull: Pulling "@keeb/grafana"@"2026.07.18.1"
INF extension·pull: Identity verified: "@keeb/grafana"@"2026.07.18.1"
INF extension·pull: Pulled "@keeb/grafana"@"2026.07.18.1"
INF extension·pull: Extracted 7 files:

Find the dashboard UID

Open the dashboard in Grafana. The UID is the path segment after /d/ in its URL. For a dashboard at /d/service-overview/service-overview, the UID is service-overview.

If you do not have the dashboard open, the discover method of the behavior lists the dashboards on the server.

Export the dashboard

Run exportDashboard with the UID and the path to write in the repository:

swamp behavior run grafana exportDashboard \
  --input dashboardUid=service-overview \
  --input outputFile=dashboards/service-overview.json

This command needs a reachable Grafana server. It fetches the dashboard from Grafana, writes it to dashboards/service-overview.json in the repository, and writes the export result to the dashboard resource.

Review and commit the file

Open dashboards/service-overview.json and check the panels and variables. Commit the file to version control.

To send an edited version back to Grafana, follow Push a dashboard JSON file to Grafana with the same file path.

Refer to the Grafana extensions reference for every method and argument.