feat(ext): add json encoder#1340
Conversation
| // Examples: | ||
| // | ||
| // json.encode({'hello': 'world'}) // return '{"hello":"world"}' | ||
| func Encoders(options ...EncodersOption) cel.EnvOption { |
There was a problem hiding this comment.
Please make sure to add a new version bump for the added encoder.
There was a problem hiding this comment.
Done. Added json.encode as encoder version 1, gated it behind EncodersVersion(1), and added version tests.
go test ./ext passes locally.
| // | ||
| // Examples: | ||
| // | ||
| // json.encode({'hello': 'world'}) // return '{"hello":"world"}' |
There was a problem hiding this comment.
Would you also mind adding this documentation into the ext/README.md as well?
|
/gcbrun |
|
Added the JSON encoder docs to ext/README.md. |
|
/gcbrun |
| "github.com/google/cel-go/cel" | ||
| "github.com/google/cel-go/common/types" | ||
| "github.com/google/cel-go/common/types/ref" | ||
| "google.golang.org/protobuf/encoding/protojson" |
There was a problem hiding this comment.
You'll need to update the BUILD.bazel with the protojson dep in the go_default_library build target.
"@org_golang_google_protobuf//encoding/protojson:go_default_library",
To verify run bazel test //...
There was a problem hiding this comment.
Done. Added the missing protojson Bazel dep to ext:go_default_library and verified with bazel test //....
What changed
json.encode(dyn) -> stringtoext.Encoders().JSONValueTypeconversion andprotojsonmarshaling.Why
This adds a small JSON serialization helper without pulling YAML or decoding into the same change.
Part of #1245.
Testing