Skip to content

jq backend parser #1143

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/kind-lions-notice.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'grafana-infinity-datasource': minor
---

Added support for **jq** syntax in root selector via `jq-backend` parser. To learn more, refer the [documentation](https://grafana.com/docs/plugins/yesoreyeram-infinity-datasource/latest/query/jq-backend/).
15 changes: 12 additions & 3 deletions docs/sources/query/_index.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,18 @@ weight: 300

# Query

- [Backend Parser](./backend)
- [UQL Parser](./uql)
- [GROQ Parser](./groq)
## Parsing data

- [JSONata - Backend Parser](./backend)
- [JQ - Backend Parser](./jq-backend)
- [UQL - Frontend Parser](./uql)
- [GROQ - Frontend Parser](./groq)

## Filtering data, Macros

- [Filtering data](./filters)
- [Macros](./macros)

## Time formats

- [Time formats](./time-formats)
21 changes: 8 additions & 13 deletions docs/sources/query/backend.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
---
slug: '/backend'
title: 'Backend Parser'
menuTitle: Backend Parser
description: Backend Parser
aliases:
- infinity
title: 'JSONata backend parser'
menuTitle: JSONata backend parser
description: JSONata backend parser
keywords:
- data source
- infinity
Expand All @@ -16,25 +14,22 @@ keywords:
- html
- api
- rest
- jsonata
labels:
products:
- oss
weight: 301
---

# Backend Parser
# JSONata (backend parser)

Backend parser for infinity is introduced in version 1.0.0. Setting the parser to backend in your query editor will allow you to use features such as `alerting`, `grafana expressions` ,`recorded queries`, `enterprise query caching` and `shared dashboards`.
JSONata backend parser helps you to manipulate the data using JSONata style syntax. You have to select JSONata/backend as the parser type in the query editor.

> Support for backend parser is available for JSON from version 1.0.0.
> Support for backend parser is available for CSV/TSV/GraphQL from version 1.1.0.
> Support for backend parser is available for XML/HTML from version 1.2.0.
Setting the parser to JSONata/backend allow you to use features such as [Alerting](https://grafana.com/docs/grafana/latest/alerting/), [Shared Dashboards](https://grafana.com/docs/grafana/latest/dashboards/share-dashboards-panels/shared-dashboards/), [SQL Expressions](https://grafana.com/docs/grafana/latest/panels-visualizations/query-transform-data/sql-expressions/), [Query Caching](https://grafana.com/docs/grafana/latest/administration/data-source-management/#query-and-resource-caching), [Recorded Queries](https://grafana.com/docs/grafana/latest/administration/recorded-queries/).

## Root selector/Field selector

For JSON, data received from the server should be in array format. If not, then the array must be specified by the root selector. Root selector must be in the format specified by [gjson](https://github.com/tidwall/gjson#path-syntax).

> Backend parser uses `gjson` style selectors and legacy/default/frontend parser uses `lodash` type selectors.
Root selector allows you to manipulate the data received from the server. You can use [JSONata style syntax](https://docs.jsonata.org/overview.html) in root selector to manipulate your data.

## Computed fields

Expand Down
95 changes: 95 additions & 0 deletions docs/sources/query/jq-backend.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
---
slug: '/jq-backend'
title: 'JQ backend parser'
menuTitle: JQ backend parser
description: JQ backend parser
keywords:
- data source
- infinity
- json
- graphql
- csv
- tsv
- xml
- html
- api
- rest
- jq
labels:
products:
- oss
weight: 302
---

# JQ (backend parser)

JQ backend parser helps you to manipulate the data using JQ style syntax. You have to select JQ/jq-backend as the parser type in the query editor.

Setting the parser to JQ/jq-backend allow you to use features such as [Alerting](https://grafana.com/docs/grafana/latest/alerting/), [Shared Dashboards](https://grafana.com/docs/grafana/latest/dashboards/share-dashboards-panels/shared-dashboards/), [SQL Expressions](https://grafana.com/docs/grafana/latest/panels-visualizations/query-transform-data/sql-expressions/), [Query Caching](https://grafana.com/docs/grafana/latest/administration/data-source-management/#query-and-resource-caching), [Recorded Queries](https://grafana.com/docs/grafana/latest/administration/recorded-queries/).

This parser is very similar to jsonata backend parser where you use [JSONata style syntax](https://docs.jsonata.org/overview.html) in root selector. But with JQ backend parser, you will be using [jq style syntax](https://jqlang.org/tutorial/) in the root selector.

## Examples

### Manipulating simple JSON array

```json
[
{
"name": "foo",
"age": 123
},
{
"name": "bar",
"age": 456
}
]
```

and the root selector `.[]` will produce the following output

| age | name |
| --- | ---- |
| 123 | foo |
| 456 | bar |

### Manipulating nested JSON object

```json
{
"meta": {
"hello": "world"
},
"data": [
{
"name": "foo",
"age": 123
},
{
"name": "bar",
"age": 456
}
]
}
```

and the root selector `.data[]` will produce the following output

| age | name |
| --- | ---- |
| 123 | foo |
| 456 | bar |

For more examples and to learn more about jq syntax, refer official [jq documentation](https://jqlang.org/tutorial).

## Computed fields

Computed fields option with JQ parser works similar to JSONata parser

## Filter

Filter option with JQ parser works similar to JSONata parser

## Summarize

Summarize option with JQ parser works similar to JSONata parser
81 changes: 41 additions & 40 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@ require (
github.com/grafana/dskit v0.0.0-20250306142006-a53bcf294bdf
github.com/grafana/grafana-aws-sdk v0.31.2
github.com/grafana/grafana-plugin-sdk-go v0.277.0
github.com/grafana/infinity-libs/lib/go/csvframer v1.0.1
github.com/grafana/infinity-libs/lib/go/framesql v1.0.2
github.com/grafana/infinity-libs/lib/go/gframer v1.0.0
github.com/grafana/infinity-libs/lib/go/jsonframer v1.1.4
github.com/grafana/infinity-libs/lib/go/macros v1.0.1
github.com/grafana/infinity-libs/lib/go/transformations v1.0.3
github.com/grafana/infinity-libs/lib/go/xmlframer v1.0.0
github.com/grafana/infinity-libs/lib/go/csvframer v1.0.3
github.com/grafana/infinity-libs/lib/go/framesql v1.0.3
github.com/grafana/infinity-libs/lib/go/gframer v1.1.2
github.com/grafana/infinity-libs/lib/go/jsonframer v1.3.0
github.com/grafana/infinity-libs/lib/go/macros v1.0.3
github.com/grafana/infinity-libs/lib/go/transformations v1.0.6
github.com/grafana/infinity-libs/lib/go/xmlframer v1.0.3
github.com/icholy/digest v0.1.22
github.com/stretchr/testify v1.10.0
go.opentelemetry.io/otel v1.35.0
Expand All @@ -23,9 +23,9 @@ require (
)

require (
github.com/Azure/azure-sdk-for-go/sdk/azcore v1.10.0 // indirect
github.com/Azure/azure-sdk-for-go/sdk/azcore v1.9.2 // indirect
github.com/Azure/azure-sdk-for-go/sdk/internal v1.5.2 // indirect
github.com/BurntSushi/toml v1.4.0 // indirect
github.com/BurntSushi/toml v1.5.0 // indirect
github.com/apache/arrow-go/v18 v18.2.0 // indirect
github.com/araddon/dateparse v0.0.0-20210429162001-6b43995a97de // indirect
github.com/aws/aws-sdk-go v1.51.31 // indirect
Expand All @@ -34,16 +34,16 @@ require (
github.com/cenkalti/backoff/v4 v4.3.0 // indirect
github.com/cespare/xxhash/v2 v2.3.0 // indirect
github.com/cheekybits/genny v1.0.0 // indirect
github.com/chromedp/cdproto v0.0.0-20240810084448-b931b754e476 // indirect
github.com/cpuguy83/go-md2man/v2 v2.0.5 // indirect
github.com/chromedp/cdproto v0.0.0-20250221214400-5cdcd25b55f6 // indirect
github.com/cpuguy83/go-md2man/v2 v2.0.7 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/elazarl/goproxy v1.7.2 // indirect
github.com/fatih/color v1.17.0 // indirect
github.com/getkin/kin-openapi v0.131.0 // indirect
github.com/fatih/color v1.18.0 // indirect
github.com/getkin/kin-openapi v0.132.0 // indirect
github.com/go-logr/logr v1.4.2 // indirect
github.com/go-logr/stdr v1.2.2 // indirect
github.com/go-openapi/jsonpointer v0.21.0 // indirect
github.com/go-openapi/swag v0.23.0 // indirect
github.com/go-openapi/jsonpointer v0.21.1 // indirect
github.com/go-openapi/swag v0.23.1 // indirect
github.com/goccy/go-json v0.10.5 // indirect
github.com/gogo/protobuf v1.3.2 // indirect
github.com/golang/protobuf v1.5.4 // indirect
Expand All @@ -52,26 +52,28 @@ require (
github.com/google/uuid v1.6.0 // indirect
github.com/gorilla/mux v1.8.1 // indirect
github.com/grafana/dataplane/sdata v0.0.9 // indirect
github.com/grafana/infinity-libs/lib/go/utils v1.0.0 // indirect
github.com/grafana/infinity-libs/lib/go/utils v1.0.1 // indirect
github.com/grafana/otel-profiling-go v0.5.1 // indirect
github.com/grafana/pyroscope-go/godeltaprof v0.1.8 // indirect
github.com/grafana/sqlds/v4 v4.1.0 // indirect
github.com/grpc-ecosystem/go-grpc-middleware/providers/prometheus v1.0.1 // indirect
github.com/grpc-ecosystem/go-grpc-middleware/v2 v2.3.1 // indirect
github.com/grpc-ecosystem/grpc-gateway/v2 v2.26.1 // indirect
github.com/grpc-ecosystem/go-grpc-middleware/v2 v2.3.2 // indirect
github.com/grpc-ecosystem/grpc-gateway/v2 v2.26.3 // indirect
github.com/hashicorp/go-hclog v1.6.3 // indirect
github.com/hashicorp/go-plugin v1.6.3 // indirect
github.com/hashicorp/yamux v0.1.1 // indirect
github.com/hashicorp/yamux v0.1.2 // indirect
github.com/itchyny/gojq v0.12.17 // indirect
github.com/itchyny/timefmt-go v0.1.6 // indirect
github.com/jmespath/go-jmespath v0.4.0 // indirect
github.com/josharian/intern v1.0.0 // indirect
github.com/json-iterator/go v1.1.12 // indirect
github.com/jszwedko/go-datemath v0.1.1-0.20230526204004-640a500621d6 // indirect
github.com/klauspost/compress v1.18.0 // indirect
github.com/klauspost/cpuid/v2 v2.2.10 // indirect
github.com/magefile/mage v1.15.0 // indirect
github.com/mailru/easyjson v0.7.7 // indirect
github.com/mailru/easyjson v0.9.0 // indirect
github.com/mattetti/filebuffer v1.0.1 // indirect
github.com/mattn/go-colorable v0.1.13 // indirect
github.com/mattn/go-colorable v0.1.14 // indirect
github.com/mattn/go-isatty v0.0.20 // indirect
github.com/mattn/go-runewidth v0.0.16 // indirect
github.com/mitchellh/go-homedir v1.1.0 // indirect
Expand All @@ -92,22 +94,21 @@ require (
github.com/perimeterx/marshmallow v1.1.5 // indirect
github.com/pierrec/lz4/v4 v4.1.22 // indirect
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect
github.com/prometheus/client_golang v1.20.5 // indirect
github.com/prometheus/client_model v0.6.1 // indirect
github.com/prometheus/client_golang v1.22.0 // indirect
github.com/prometheus/client_model v0.6.2 // indirect
github.com/prometheus/common v0.63.0 // indirect
github.com/prometheus/procfs v0.15.1 // indirect
github.com/prometheus/procfs v0.16.1 // indirect
github.com/rivo/uniseg v0.4.7 // indirect
github.com/russross/blackfriday/v2 v2.1.0 // indirect
github.com/shopspring/decimal v1.4.0 // indirect
github.com/smartystreets/goconvey v1.7.2 // indirect
github.com/tidwall/gjson v1.17.1 // indirect
github.com/tidwall/gjson v1.18.0 // indirect
github.com/tidwall/match v1.1.1 // indirect
github.com/tidwall/pretty v1.2.1 // indirect
github.com/unknwon/bra v0.0.0-20200517080246-1e3013ecaff8 // indirect
github.com/unknwon/com v1.0.1 // indirect
github.com/unknwon/log v0.0.0-20200308114134-929b1006e34a // indirect
github.com/urfave/cli v1.22.16 // indirect
github.com/xiatechs/jsonata-go v1.8.7 // indirect
github.com/xiatechs/jsonata-go v1.8.8 // indirect
github.com/zeebo/xxh3 v1.0.2 // indirect
go.opentelemetry.io/auto/sdk v1.1.0 // indirect
go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc v0.60.0 // indirect
Expand All @@ -118,21 +119,21 @@ require (
go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc v1.35.0 // indirect
go.opentelemetry.io/otel/metric v1.35.0 // indirect
go.opentelemetry.io/otel/sdk v1.35.0 // indirect
go.opentelemetry.io/proto/otlp v1.5.0 // indirect
go.opentelemetry.io/proto/otlp v1.6.0 // indirect
go.uber.org/atomic v1.10.0 // indirect
golang.org/x/crypto v0.37.0 // indirect
golang.org/x/exp v0.0.0-20240909161429-701f63a606c0 // indirect
golang.org/x/mod v0.23.0 // indirect
golang.org/x/net v0.39.0 // indirect
golang.org/x/sync v0.13.0 // indirect
golang.org/x/sys v0.32.0 // indirect
golang.org/x/term v0.31.0 // indirect
golang.org/x/text v0.24.0 // indirect
golang.org/x/tools v0.30.0 // indirect
golang.org/x/crypto v0.38.0 // indirect
golang.org/x/exp v0.0.0-20250506013437-ce4c2cf36ca6 // indirect
golang.org/x/mod v0.24.0 // indirect
golang.org/x/net v0.40.0 // indirect
golang.org/x/sync v0.14.0 // indirect
golang.org/x/sys v0.33.0 // indirect
golang.org/x/term v0.32.0 // indirect
golang.org/x/text v0.25.0 // indirect
golang.org/x/tools v0.33.0 // indirect
golang.org/x/xerrors v0.0.0-20240903120638-7835f813f4da // indirect
google.golang.org/genproto/googleapis/api v0.0.0-20250218202821-56aae31c358a // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20250218202821-56aae31c358a // indirect
google.golang.org/grpc v1.71.1 // indirect
google.golang.org/genproto/googleapis/api v0.0.0-20250505200425-f936aa4a68b2 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20250505200425-f936aa4a68b2 // indirect
google.golang.org/grpc v1.72.0 // indirect
google.golang.org/protobuf v1.36.6 // indirect
gopkg.in/Knetic/govaluate.v3 v3.0.0 // indirect
gopkg.in/fsnotify/fsnotify.v1 v1.4.7 // indirect
Expand Down
Loading
Loading