-
Notifications
You must be signed in to change notification settings - Fork 487
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Added json_path function * Add doc note about local.file * Update docs/sources/flow/reference/stdlib/json_path.md Co-authored-by: Clayton Cornell <[email protected]> --------- Co-authored-by: Clayton Cornell <[email protected]>
- Loading branch information
1 parent
c207f80
commit fe2f702
Showing
6 changed files
with
88 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
--- | ||
aliases: | ||
- ../../configuration-language/standard-library/json_path/ | ||
title: json_path | ||
--- | ||
|
||
# json_path | ||
|
||
The `json_path` function lookup values using [jsonpath](https://goessner.net/articles/JsonPath/) syntax. | ||
|
||
The function expects two strings. The first string is the JSON string used look up values. The second string is the jsonpath expression. | ||
|
||
`json_path` always returns a list of values. If the jsonpath expression does not match any values, an empty list is returned. | ||
|
||
A common use case of `json_path` is to decode and filter the output of a [`local.file`][] or [`remote.http`][] component to a River value. | ||
|
||
> Remember to escape double quotes when passing JSON string literals to `json_path`. | ||
> | ||
> For example, the JSON value `{"key": "value"}` is properly represented by the | ||
> string `"{\"key\": \"value\"}"`. | ||
## Examples | ||
|
||
``` | ||
> json_path("{\"key\": \"value\"}", ".key") | ||
["value"] | ||
> json_path("[{\"name\": \"Department\",\"value\": \"IT\"},{\"name\":\"TestStatus\",\"value\":\"Pending\"}]", "[?(@.name == \"Department\")].value") | ||
["IT"] | ||
> json_path("{\"key\": \"value\"}", ".nonexists") | ||
[] | ||
> json_path("{\"key\": \"value\"}", ".key")[0] | ||
value | ||
``` | ||
|
||
[`local.file`]: {{< relref "../components/local.file.md" >}} | ||
[`remote.http`]: {{< relref "../components/remote.http.md" >}} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters