Skip to content

feat(ext): add json encoder#1340

Open
rohan-patnaik wants to merge 2 commits into
cel-expr:masterfrom
rohan-patnaik:rpatnaik/cel-json-encoder
Open

feat(ext): add json encoder#1340
rohan-patnaik wants to merge 2 commits into
cel-expr:masterfrom
rohan-patnaik:rpatnaik/cel-json-encoder

Conversation

@rohan-patnaik

Copy link
Copy Markdown
Contributor

What changed

  • Added json.encode(dyn) -> string to ext.Encoders().
  • Uses the existing CEL JSONValueType conversion and protojson marshaling.
  • Added tests for string, list, and object values.

Why

This adds a small JSON serialization helper without pulling YAML or decoding into the same change.

Part of #1245.

Testing

  • go test ./ext -run 'TestEncoders'

Comment thread ext/encoders.go
// Examples:
//
// json.encode({'hello': 'world'}) // return '{"hello":"world"}'
func Encoders(options ...EncodersOption) cel.EnvOption {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please make sure to add a new version bump for the added encoder.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done. Added json.encode as encoder version 1, gated it behind EncodersVersion(1), and added version tests.

go test ./ext passes locally.

@rohan-patnaik rohan-patnaik marked this pull request as ready for review June 16, 2026 00:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants