Skip to content
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

Add fromJson to the template stage. #3736

Merged
merged 1 commit into from
May 25, 2021
Merged
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
16 changes: 16 additions & 0 deletions docs/sources/logql/template_functions.md
Original file line number Diff line number Diff line change
Expand Up @@ -595,3 +595,19 @@ Signature: `toFloat64(v interface{}) float64`
```template
{{ "3.5" | float64 }} //output 3.5
```

## fromJson

> **Note:** Added in Loki 2.3.

fromJson decodes a JSON document into a structure. If the input cannot be decoded as JSON the function will return an empty string.

```template
fromJson "{\"foo\": 55}"
```

Example of a query to print a newline per queries stored as a json array in the log line:

```logql
{job="cortex/querier"} |= "finish in prometheus" | logfmt | line_format "{{ range $q := fromJson .queries }} {{ $q.query }} {{ end }}"
```
1 change: 1 addition & 0 deletions pkg/logql/log/fmt.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ var (
"ceil",
"floor",
"round",
"fromJson",
}
)

Expand Down