Skip to content

Adding ability to use JSON Names for pb fields#1220

Closed
renevo wants to merge 1 commit into
cel-expr:masterfrom
Blizzard:json-fieldname-option
Closed

Adding ability to use JSON Names for pb fields#1220
renevo wants to merge 1 commit into
cel-expr:masterfrom
Blizzard:json-fieldname-option

Conversation

@renevo

@renevo renevo commented Sep 25, 2025

Copy link
Copy Markdown

This adds a simple variable to map the fields to the JSONName() instead of Name() on the protobuf field descriptors.

This allows for using cel expressions against the same JSON representations in some scenarios.

The default behavior is identical. Test has been added to validate field names with setting turned on and all tests pass.

Closes #1214

This adds a simple variable to map the fields to the JSONName() instead of
Name() on the protobuf field descriptors.

This allows for using cel expressions against the same JSON
representations in some scenarios.

The default behavior is identical. Test has been added to validate field
names with setting turned on.
@renevo renevo force-pushed the json-fieldname-option branch from 2905c5e to c81c195 Compare September 25, 2025 23:05
@renevo

renevo commented Oct 13, 2025

Copy link
Copy Markdown
Author

Is there more information/work I can do on this PR to move one way or the other?

@TristonianJones

Copy link
Copy Markdown
Collaborator

/gcbrun

Comment thread common/types/pb/type.go
for i := 0; i < fields.Len(); i++ {
f := fields.Get(i)
fieldMap[string(f.Name())] = newFieldDescription(f)
if UseJSONFieldNames {

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.

If you move this flag up as a function argument, you should be able to pass the same argument into the pb.Db instance which generates the internal type descriptions.

@TristonianJones TristonianJones Oct 14, 2025

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.

Specifically, you'll want to update the common/types/pb.go definition for the ``Db` struct:

type fieldNameKind int

const (
   fieldNameKind proto = iota
   json
   jsonOrProto
)

type Db struct {
	revFileDescriptorMap map[string]*FileDescription
	// files contains the deduped set of FileDescriptions whose types are contained in the pb.Db.
	files []*FileDescription
	// extensions contains the mapping between a given type name, extension name and its FieldDescription
	extensions map[string]map[string]*FieldDescription
	
	// fieldNameConvention supports type resolution using either the protobuf name or its JSON name
    fieldNameConvention fieldNameKind
}

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.

You would then need to support a functional option to the NewDb call:

// NewDb creates a new `pb.Db` with an empty type name to file description map.
func NewDb(DbOption ...opts) *Db {
	pbdb := &Db{ ... }
	for _, opt := range opts {
	   pbdb = opt(pbdb)
	}

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

let me look into that, thanks for the response.

@renevo

renevo commented Mar 19, 2026

Copy link
Copy Markdown
Author

This was implemented in #1286 closing this out

@renevo renevo closed this Mar 19, 2026
@renevo renevo deleted the json-fieldname-option branch March 19, 2026 14:05
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.

Support JSON Name in pb field names

2 participants