Preserve empty Go slices and maps in JSON#1528
Merged
Merged
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
Note
Copilot was unable to run its full agentic suite in this review.
Updates Go JSON serialization semantics to distinguish between nil and empty values for slice/map fields by emitting omitzero tags (and generating them via codegen), with tests validating the behavior.
Changes:
- Add Go codegen helpers to generate
jsontags usingomitzerofor optional slice/map fields. - Update Go struct tags for slice/map fields to use
,omitzero(omit only when nil/zero). - Add Go tests covering nil vs empty serialization for affected fields.
Show a summary per file
| File | Description |
|---|---|
| scripts/codegen/go.ts | Centralizes JSON tag generation and switches optional slice/map fields to omitzero semantics. |
| go/types.go | Updates struct tags (and comments) to preserve empty slice/map values while omitting nils. |
| go/canvas.go | Updates InputSchema tag to ,omitzero for nil vs empty behavior. |
| go/types_test.go | Adds tests asserting nil fields are omitted while empty slice/map fields are included. |
Copilot's findings
Files not reviewed (4)
- go/rpc/zrpc.go: Language not supported
- go/rpc/zrpc_encoding.go: Language not supported
- go/rpc/zsession_encoding.go: Language not supported
- go/rpc/zsession_events.go: Language not supported
- Files reviewed: 4/8 changed files
- Comments generated: 5
stephentoub
approved these changes
Jun 1, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Use Go's
json:",omitzero"tag for optional generated slices/maps, and for hand-authored public fields where an empty-but-present value has distinct wire semantics.This preserves the difference between:
Why
omitemptycollapses nil and empty slices/maps into the same JSON shape by omitting both. That loses information for APIs where "not provided" and "provided but empty" mean different things.omitzerokeeps nil as absent while allowing callers to intentionally send empty arrays/objects.Concrete examples:
CustomAgentConfig.Tools[]: explicitly expose no toolsTool.Parameters{}: an explicit JSON Schema object that accepts any parametersCanvasDeclaration.InputSchema{}: explicit schema accepting any canvas inputElicitationResult.Content{}: accepted form with no fields/valuesThe generated Go code now applies this consistently to optional slices/maps, while scalar/pointer optionals continue to use
omitempty.Testing
cd scripts/codegen && npm run generate:gocd go && go testcd nodejs && npm test -- session-event-codegen.test.tsCustomAgentConfig,Tool,CanvasDeclaration, andElicitationResultvalues