Grafana: Library Panels, JSON Model and Versions
|
This content was generated with the assistance of AI and should be verified against the official documentation before being relied on in production. |
Checked on 2026-11-09 against Grafana 13.3.x.
To do this by hand, follow Reuse, Versions and Sharing.
A dashboard that matters for production is an artefact like any other: it is reused (the same "5xx ratio" panel on twenty service dashboards), moved between environments, reviewed, and sometimes broken by an edit at the worst moment. Four Grafana features cover those needs. Library panels make one panel definition shared by many dashboards. The JSON model is the dashboard’s real definition, which makes it diffable and scriptable. Export and import move dashboards between instances and from the public catalogue. Version history lets anyone undo a bad save. This page explains each, with the Bookshelf "Bookshelf service health" dashboard as the running example; provisioning and Git-based workflows built on the same JSON are in Grafana: Observability as Code and the general ideas in Observability as Code.
Library panels
A library panel is a panel stored once and referenced by any number of dashboards. Editing it from any dashboard that uses it changes it everywhere, and library panels are stored in folders next to dashboards and protected by role-based access control.
-
Create: in edit mode, open the panel’s More menu and choose New library panel, name it, choose a folder and select Create library panel. The source panel becomes a library panel, so the original dashboard must be saved afterwards.
-
Use: on a new or existing dashboard add a panel and choose Use library panel, then pick it from the drawer.
-
Update: edit it from any dashboard that uses it; all instances change when saved.
-
Unlink: More > Unlink library panel turns this dashboard’s copy into an ordinary panel so it can diverge without affecting others.
-
Replace: More > Replace library panel swaps in another library panel.
-
Manage: Dashboards > Library panels lists them with filters by folder and type and shows which dashboards use each one.
The strength of a library panel is also its risk. A change to the shared "5xx ratio" panel is a change to every dashboard that shows it, including ones owned by other teams, with no review step of its own. Use library panels for definitions that should be identical everywhere (the SLO burn-rate panel, the golden-signal row of a standard service dashboard), keep them in a folder with restricted edit rights, and do not use them for panels that each team tunes. Library panels are not available on externally shared dashboards (see Sharing and Reporting).
The JSON model
Every dashboard is a JSON document. Grafana 13 knows three shapes, and which one you meet depends on where it came from:
| Model | Notes |
|---|---|
V2 Resource (current) |
Models every dashboard element as a Kubernetes-style kind; supports the newer features such as advanced layouts and conditional rendering. The Observability as Code tooling is fully compatible only with this model. |
V1 Resource |
The Classic model wrapped in a Kubernetes-style resource, with the Classic content under |
Classic |
The older, non-Kubernetes format and the default before 12.2.0. It is the format of most dashboards on grafana.com. A Classic dashboard can be exported as Classic or V2. |
The JSON is reached from edit mode: Edit > Dashboard options > View all settings > JSON Model, change it, select Save changes, then Back and Exit edit. Grafana 13 also makes dynamic dashboards the default (generally available), and dashboards migrate to the new schema when they are opened.
Source: Grafana: View dashboard JSON model. The 13.0 behaviour is described in What’s new in 13.0.
The Classic model
The Classic fields worth knowing are: uid (8 to 40 characters, anyone may generate it; stable across instances, which is why links and provisioning use it), id
(a database-generated number, null until the first save, never use it in code), title, tags, timezone, graphTooltip (0 no shared crosshair, 1 shared crosshair, 2 shared crosshair and tooltip), time (default range),
timepicker (including refresh_intervals and nowDelay), templating.list (variables), annotations.list, refresh, links, panels (each with gridPos: 24 columns, h in units of 30 pixels, negative
gravity so panels float up), schemaVersion (changes when a Grafana update changes the schema) and version (increments on each save). The uid, the schema fields and a clean templating block are the usual sources
of noisy diffs.
Source: Classic model.
The V1 Resource model
A V1 Resource has apiVersion: dashboard.grafana.app/v1, kind: Dashboard, a metadata block (name, namespace, uid, resourceVersion, generation, annotations such as grafana.app/folder) and a spec
holding the Classic content (with schemaVersion 42 in the documented example). When a tool asks for "the full Kubernetes-style document", this is the shape.
Source: V1 Resource model.
A minimal V2 Resource
In V2 the dashboard spec has elements (panels and library panels, keyed by name), a layout that references them, variables, annotations, links, timeSettings, tags and title. The example
below is a complete dashboard with one panel, one variable and a grid layout, written against the published V2 schema; field names come from the schema, the data source name and query are Bookshelf lab values.
{
"apiVersion": "dashboard.grafana.app/v2",
"kind": "Dashboard",
"metadata": {
"name": "bookshelf-service-health"
},
"spec": {
"title": "Bookshelf service health",
"tags": ["bookshelf"],
"cursorSync": "Crosshair",
"annotations": [],
"links": [],
"variables": [
{
"kind": "CustomVariable",
"spec": {
"name": "env",
"query": "prod,staging",
"current": { "text": "prod", "value": "prod" },
"options": [],
"multi": false,
"includeAll": false,
"hide": "dontHide",
"skipUrlSync": false,
"allowCustomValue": true
}
}
],
"elements": {
"panel-requests": {
"kind": "Panel",
"spec": {
"id": 1,
"title": "Requests per second",
"links": [],
"data": {
"kind": "QueryGroup",
"spec": {
"queries": [
{
"kind": "PanelQuery",
"spec": {
"refId": "A",
"hidden": false,
"query": {
"kind": "DataQuery",
"group": "prometheus",
"version": "v0",
"datasource": { "name": "prometheus" },
"spec": {
"expr": "sum(rate(http_server_requests_seconds_count{application=\"bookshelf\"}[$__rate_interval]))"
}
}
}
}
],
"transformations": [],
"queryOptions": {}
}
},
"vizConfig": {
"kind": "VizConfig",
"group": "timeseries",
"version": "13.3.0",
"spec": {
"options": {},
"fieldConfig": { "defaults": {}, "overrides": [] }
}
}
}
}
},
"layout": {
"kind": "GridLayout",
"spec": {
"items": [
{
"kind": "GridLayoutItem",
"spec": {
"x": 0, "y": 0, "width": 12, "height": 8,
"element": { "kind": "ElementReference", "name": "panel-requests" }
}
}
]
}
},
"timeSettings": {
"from": "now-6h",
"to": "now",
"timezone": "browser",
"autoRefresh": "",
"autoRefreshIntervals": ["5s", "10s", "30s", "1m", "5m"],
"hideTimepicker": false,
"fiscalYearStartMonth": 0
}
}
}
A library panel appears in elements as a reference by name and uid instead of an inline definition:
"panel-5xx": {
"kind": "LibraryPanel",
"spec": {
"id": 2,
"title": "5xx ratio",
"libraryPanel": { "name": "5xx ratio", "uid": "REPLACE_WITH_LIBRARY_PANEL_UID" }
}
}
Variables in V2 are an array of kinds (QueryVariable, CustomVariable, TextVariable, ConstantVariable, DatasourceVariable, IntervalVariable,
GroupByVariable, AdhocVariable, SwitchVariable), and repeats are options of the layout item, row or tab. The schema is versioned (v2alpha1, v2beta1, v2); the Grafana source repository
is the authority for the fields, so validate a hand-written document by importing it into a lab instance rather than trusting it.
Source: Grafana source: dashboard V2 spec (CUE) and V2 Resource model.
Why read the JSON at all
Three situations justify opening the JSON: finding why a panel misbehaves (a hidden override or transformation), making a mechanical change across many panels (renaming a label), and reviewing a
change in a pull request. Prefer the UI for design work; prefer JSON for diffing. Whatever you do, keep the dashboard uid stable, since alert rules, links, library panels and provisioning all point at it.
Export and import
Export as code produces Classic JSON or the V2 Resource model (JSON or YAML for V2). The option Share dashboard with another instance strips instance-specific details such as data source identifiers, replacing them with import inputs, which is what you want for a catalogue or another environment. To publish a dashboard on grafana.com, export it with the Classic model.
Import (Dashboards > New > Import) accepts a grafana.com dashboard URL or ID with Load, an uploaded JSON file, or pasted JSON. During import you can change the dashboard name, folder and UID, and map each data source input to a data source in your instance. The grafana.com catalogue (https://grafana.com/grafana/dashboards/) contains official and community dashboards; they save time but carry that community’s naming and metric assumptions, so check every query against your own labels (for example, a community JVM dashboard may expect different metric names than the Bookshelf’s Micrometer series) before relying on it for an alert-critical view. The HTTP API can also import dashboards, which is how pipelines load them.
Source: Grafana: Import dashboards and Export a dashboard as code.
Template dashboards and suggested dashboards
Grafana can also start a dashboard from a template (Dashboards > New > Dashboard from template): a pre-built layout filled with sample data and a banner panel that you remove once you point each panel at your own data source and queries. Suggested dashboards (Connections > Data sources > Build a dashboard > From suggestions) are dashboards matched to a configured data source, provided by the plugin or the community, and Prometheus suggestions are scored by comparing your metrics with those the dashboard expects. Both features are in public preview with limited support, so do not make them part of a production process. The Grafana Assistant customisation of templates is Grafana Cloud only.
Version history
Each time a dashboard is saved, Grafana keeps a copy. In Edit > Dashboard options > View all settings > Versions you can select two versions and Compare versions for a text summary, expand View JSON diff for the raw
change, and Restore a version. Restoring saves immediately and exits edit mode, and it creates a new version with the old content (the Notes column marks it), so history is never rewritten. The
number kept per dashboard is the versions_to_keep setting in the [dashboards] section of the configuration (default 20, minimum 1).
[dashboards]
versions_to_keep = 50
Twenty versions can be exhausted in a day of active editing, after which the version that was last known good is gone. Raise the value on instances where people edit by hand, write a change description on every save (the save dialog accepts one), and treat Git as the durable history if you provision dashboards from files or Git Sync.
What can go wrong
-
Editing a library panel breaks other teams' dashboards. Restrict who can edit the folder, or unlink where each team needs its own copy.
-
A library panel deleted while in use. Check its usage in Dashboards > Library panels before deleting, since every dashboard that shows it is affected.
-
Import fails or shows "No data". A data source input was left unmapped, or the dashboard targets metrics your system does not expose.
-
Diffs full of noise.
version,schemaVersion, saved variable selections and panel ids change on every save; normalise them before committing. -
Hand-edited JSON is rejected or silently migrated. Grafana migrates schemas when a dashboard opens; validate in a lab instance first.
-
Restore did not bring back the data. It restores the dashboard definition only, not annotations, data or alert rules.
Verify in the lab
-
Turn the "5xx ratio" panel of "Bookshelf service health" into a library panel, add it to a second dashboard, change its threshold in one and confirm the other changes.
-
Unlink it on the second dashboard, change it again and confirm the first dashboard is unaffected.
-
Open JSON Model, change the title, save, then open Versions, compare the two latest versions with View JSON diff and restore the earlier one.
-
Export the dashboard with Share dashboard with another instance enabled and import it into a different folder with a new UID.
In the books
McCollam (Getting Started with Grafana, chapter 7) shows how to add a panel to the library, use it in a dashboard, update it and unlink it; Chapman and Holmes and Hernandez mention library panels only in a tour of the menu. Salituro (Learn Grafana 10.x, chapter 10) shares a dashboard by exporting JSON and as a snapshot. The workflow still matches, but the JSON in those books is the Classic model (the V1 and V2 Resource models and Export as code with a V2 option came later), dashboards can be shared with another instance as stripped-down exports, and dashboard templates and suggested dashboards did not exist.