Skip to content

Commit

Permalink
Add yaml_decode function to stdlib
Browse files Browse the repository at this point in the history
  • Loading branch information
djcode committed Feb 5, 2024
1 parent 9607531 commit 4e953fa
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ Main (unreleased)
### Features

- Add support for raw map[string]any type to riverjson encoding. (@wildum)
- Add yaml_decode function to stdlib. (@djcode)

v0.3.0 (2023-10-26)
-------------------
Expand Down
11 changes: 11 additions & 0 deletions internal/stdlib/stdlib.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ import (
"github.com/grafana/river/rivertypes"
"github.com/ohler55/ojg/jp"
"github.com/ohler55/ojg/oj"

"gopkg.in/yaml.v3"
)

// Identifiers holds a list of stdlib identifiers by name. All interface{}
Expand Down Expand Up @@ -83,6 +85,15 @@ var Identifiers = map[string]interface{}{
return res, nil
},

"yaml_decode": func(in string) (interface{}, error) {
var res interface{}
err := yaml.Unmarshal([]byte(in), &res)
if err != nil {
return nil, err
}
return res, nil
},

"json_path": func(jsonString string, path string) (interface{}, error) {
jsonPathExpr, err := jp.ParseString(path)
if err != nil {
Expand Down

0 comments on commit 4e953fa

Please sign in to comment.