Skip to content

encoding/json/v2: remove recursive nature of string tag option #79065

Description

@dsnet

Proposal Details

The current prototype of json/v2 allows the string tag option to be recursive. For example:

json.Marshal(struct{
    Foo []int `json:",string"`
}{Foo: []int{1, 2, 3}})

would result in:

{"Foo": ["1", "2", "3"]}

This is in contrast to v1 behavior, which silently ignore the string tag option on composite Go types.

In the working group, we decided to remove the recursive nature of string since none of the other tag options are recursive in nature. With typed struct tags coming in the horizon, it increasingly looks like most tag options would be non-recursive in nature (i.e., they only affect the immediate field value). Of course, there exist reasonable use-cases where you want an option to be recursive, but we would probably design a typed-struct tag API to express that intent. Thus, the general precedence is that tags are non-recursive by default.

We will remove support for string tag option on composite types and (if running under v2-semantics, to instead report a runtime error).

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

LibraryProposalIssues describing a requested change to the Go standard library or x/ libraries, but not to a toolProposalrelease-blocker

Type

No type

Projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions