From e045af5d9c9106594bc2a5f609b14dbc603f7253 Mon Sep 17 00:00:00 2001 From: Andreas Hochsteger Date: Thu, 29 Dec 2022 23:01:05 +0100 Subject: Add coll.JQ using gojq library (#1585) * feat: add coll.JQ using gojq library * fix: jq function naming (gojq -> jq) * test: add tests (take from jsonpath_test.go) * chore: add TODO for nil values (are they allowed?) * refactor: use fmt.Errorf instead of errors.Wrapf Co-authored-by: Dave Henderson * fix: wrong alias for coll.JQ Co-authored-by: Dave Henderson * docs: add links to JQ Co-authored-by: Dave Henderson * test: add assertions after json marshal/unmarshal Co-authored-by: Dave Henderson * refactor: use fmt.Errorf instead of errors.Wrapf Co-authored-by: Dave Henderson * fix: test syntax and null handling * docs: improve documentation * docs: add blank line * Support cancellation Signed-off-by: Dave Henderson * Support (almost) all types, not just map[string]interface{} and []interface{} Signed-off-by: Dave Henderson * add an integration test for coll.JQ Signed-off-by: Dave Henderson Signed-off-by: Dave Henderson Co-authored-by: Andreas Hochsteger Co-authored-by: Dave Henderson --- funcs/coll.go | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'funcs') diff --git a/funcs/coll.go b/funcs/coll.go index 4a3ca5ab..97bf911a 100644 --- a/funcs/coll.go +++ b/funcs/coll.go @@ -47,6 +47,7 @@ func CreateCollFuncs(ctx context.Context) map[string]interface{} { f["merge"] = ns.Merge f["sort"] = ns.Sort f["jsonpath"] = ns.JSONPath + f["jq"] = ns.JQ f["flatten"] = ns.Flatten return f } @@ -142,6 +143,11 @@ func (CollFuncs) JSONPath(p string, in interface{}) (interface{}, error) { return coll.JSONPath(p, in) } +// JQ - +func (f *CollFuncs) JQ(jqExpr string, in interface{}) (interface{}, error) { + return coll.JQ(f.ctx, jqExpr, in) +} + // Flatten - func (CollFuncs) Flatten(args ...interface{}) ([]interface{}, error) { if len(args) == 0 || len(args) > 2 { -- cgit v1.2.3