Skip to content

Commit 3a2afcb

Browse files
committed
Add docs on different field lengths
1 parent 4bbab02 commit 3a2afcb

File tree

1 file changed

+37
-0
lines changed

1 file changed

+37
-0
lines changed

website/docs/query-editor.md

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,39 @@ The **Fields** tab is where you select the data to extract from the JSON documen
1818

1919
This can be useful in cases where the API returns quoted numbers, e.g. `"price": "3.49"`.
2020

21+
#### `Fields have different lengths`
22+
23+
All fields must return the same number of values. If you get this error it means that one or more of the objects is missing the queried element.
24+
25+
In the following example, the `name` property is present in both object, but `version` isn't.
26+
27+
```json
28+
{
29+
"services": [
30+
{
31+
"name": "order-api",
32+
"version": "1"
33+
},
34+
{
35+
"name": "billing-api"
36+
}
37+
]
38+
}
39+
```
40+
41+
In the example below, you can see a couple of expressions and their results for the JSON structure in the previous example. Since JSONPath expressions are evaluated individually, Grafana can't tell which version that was missing.
42+
43+
| Expression | Result |
44+
|-------------------------|--------------------------------|
45+
| `$.services[*].name` | `["order-api", "billing-api"]` |
46+
| `$.services[*].version` | `["1"]` |
47+
48+
Depending on your use case, you can use a filter expression to only return items that contain a version:
49+
50+
```json
51+
$.services[?(@.version)].name
52+
```
53+
2154
### Path
2255

2356
![Path](../static/img/editor-path.png)
@@ -55,3 +88,7 @@ Sets the text to send as a request body.
5588
- **Syntax highlighting** sets the active syntax for the editor. This is only for visual purposes and doesn't change the actual request.
5689

5790
> **Note:** Due to limitations in modern browsers, Grafana ignores the request body if the HTTP method is set to GET.
91+
92+
### Cache time
93+
94+
By default, Grafana caches the JSON document returned by the last request to avoid hitting rate limits while configuring your query. Once you're happy with your query, consider setting the cache time to **0s** to disable caching.

0 commit comments

Comments
 (0)