Add fromJson to the template stage. (#3736)

Signed-off-by: Cyril Tovena <cyril.tovena@gmail.com>
pull/3763/head
Cyril Tovena 4 years ago committed by GitHub
parent bc10123698
commit e5a3afedff
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 16
      docs/sources/logql/template_functions.md
  2. 1
      pkg/logql/log/fmt.go

@ -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 }}"
```

@ -75,6 +75,7 @@ var (
"ceil",
"floor",
"round",
"fromJson",
}
)

Loading…
Cancel
Save