@@ -29,7 +29,7 @@ func GetJSONPath(ctx EvalCtx, key string) (any, error) {
2929 subject = ctx .Subject
3030 }
3131
32- ret , err := GetJSONPathExp (key , subject )
32+ ret , err := GetJSONPathRaw (key , subject )
3333 if err != nil {
3434 return nil , err
3535 }
@@ -83,7 +83,7 @@ func SetJSONPath(ctx EvalCtx, key string, value, data any) error {
8383 }
8484
8585 // then call the low-level set util
86- if err := SetJSONPathExp (key , value , data ); err != nil {
86+ if err := SetJSONPathRaw (key , value , data ); err != nil {
8787 return fmt .Errorf ("JSONPath expression error: cannot set " +
8888 "key %q to value %q: %w" , key , value , err )
8989 }
@@ -93,9 +93,9 @@ func SetJSONPath(ctx EvalCtx, key string, value, data any) error {
9393
9494// low-level utils
9595
96- // GetJSONPathExp evaluates a JSONPath expression on the specified object and returns the result or
96+ // GetJSONPathRaw evaluates a JSONPath expression on the specified object and returns the result or
9797// an error.
98- func GetJSONPathExp (query string , object any ) (any , error ) {
98+ func GetJSONPathRaw (query string , object any ) (any , error ) {
9999 je , err := jp .ParseString (query )
100100 if err != nil {
101101 return nil , err
@@ -112,10 +112,10 @@ func GetJSONPathExp(query string, object any) (any, error) {
112112 return values [0 ], nil
113113}
114114
115- // SetJSONPathExp sets a key (possibly represented with a JSONPath expression) to a value (can also
115+ // SetJSONPathRaw sets a key (possibly represented with a JSONPath expression) to a value (can also
116116// be a JSONPath expression, which will be evaluated using the object argument) in the given data
117117// structure.
118- func SetJSONPathExp (key string , value , target any ) error {
118+ func SetJSONPathRaw (key string , value , target any ) error {
119119 je , err := jp .ParseString (key )
120120 if err != nil {
121121 return err
@@ -124,14 +124,16 @@ func SetJSONPathExp(key string, value, target any) error {
124124 return je .Set (target , value )
125125}
126126
127- // lit := []Expression{}
128- // for _, arg := range args {
129- // lit = append(lit, Expression{Op: "@any", Literal: arg, Raw: util.Stringify(arg)})
130- // }
131- // argList, err := asExpList(exp.Arg)
132- // Expect(err).NotTo(HaveOccurred())
133- // argList = append(argList, Expression{
134- // Op: "@list",
135- // Literal: lit,
136- // })
137- // exp.Arg.Literal = argList
127+ // SetJSONPathRawExp is the same as SetJSONPathRaw but takes the key as a string expression.
128+ func SetJSONPathRawExp (keyExp * Expression , value , data any ) error {
129+ key , err := keyExp .GetLiteralString ()
130+ if err != nil {
131+ return err
132+ }
133+
134+ if err := SetJSONPathRaw (key , value , data ); err != nil {
135+ return err
136+ }
137+
138+ return nil
139+ }
0 commit comments