Skip to content

Commit 8c2c500

Browse files
committed
Add JSONPath docs
1 parent 01d3cf0 commit 8c2c500

File tree

3 files changed

+60
-4
lines changed

3 files changed

+60
-4
lines changed

website/docs/jsonpath.md

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
---
2+
id: jsonpath
3+
title: JSONPath
4+
---
5+
6+
[JSONPath](https://goessner.net/articles/JsonPath/) is a query language for JSON structures.
7+
8+
For example, to query the titles of all the books in a store:
9+
10+
```js
11+
$.store.book[*].title
12+
```
13+
14+
- `$` selects the root element
15+
- `.` selects a child of the current element
16+
- `*` selects all elements within an object or array
17+
18+
:::note JSONPath Plus
19+
The JSON API data source uses the [JSONPath Plus](https://www.npmjs.com/package/jsonpath-plus) package to evaluate JSONPath expressions. JSONPath Plus extends the original specification with additional features.
20+
21+
For more information on the supported syntax, refer to the [project page](https://github.com/JSONPath-Plus/JSONPath).
22+
:::
23+
24+
## Filters
25+
26+
Filters let you query elements based on a logical expression.
27+
28+
For example, to query the titles of the books that cost more than 10:
29+
30+
```js
31+
$.store.book[?(@.price > 10)].title
32+
```
33+
34+
- `?()` defines a filter expression
35+
- `@` selects the element that's currently being processed
36+
37+
Filter expressions support a set of boolean and logical operations:
38+
39+
- Boolean operations: `!`, `&&`, `||`
40+
- Comparison: `>`, `<`, `>=`, `<=`
41+
- Equality: `==`, `!=`
42+
43+
```js
44+
$.store.book[?(@.price < 10)] // Books that are cheaper than 10
45+
$.store.book[?(@.category == 'fiction')] // Books that have the fiction category
46+
$.store.book[?(@.isbn)] // Books that have a ISBN number
47+
48+
$.store.book[?(@.price < 10 && @.category == 'fiction')] // Cheap fiction books
49+
```

website/docs/query-editor.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ The query editor for the JSON API data source consists of a number of tabs. Each
1313

1414
The **Fields** tab is where you select the data to extract from the JSON document returned by the URL configured in the data source configuration.
1515

16-
- **Field** must contain a valid JSONPath expression and can return one or more elements.
16+
- **Field** must contain a valid [JSONPath](./jsonpath.md) expression and can return one or more elements.
1717
- **Type** defines the JSON type of the elements returned by the **Field** expression. By default, Grafana uses the types in the JSON document. If **Type** is set to a different type than the original property type, Grafana tries to parse the value.
1818

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

website/sidebars.js

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,16 @@ module.exports = {
1010
items: ['installation', 'configuration'],
1111
},
1212
{
13-
type: 'category',
14-
label: 'Basics',
15-
items: ['query-editor', 'macros'],
13+
type: 'doc',
14+
id: 'query-editor',
15+
},
16+
{
17+
type: 'doc',
18+
id: 'macros',
19+
},
20+
{
21+
type: 'doc',
22+
id: 'jsonpath',
1623
},
1724
],
1825
};

0 commit comments

Comments
 (0)