Skip to content

encoding/json/v2: keep v2 and jsontext packages buildable under GOEXPERIMENT=nojsonv2 #79788

@dmitshur

Description

@dmitshur

In Go 1.26 and older, GOEXPERIMENT=jsonv2 had the effect of "make still-experimental encoding/json/v2, encoding/json/jsontext packages available, and also modify the encoding/json implementation to be implemented via the v2 packages" (release note). GOEXPERIMENT=nojsonv2 was a no-op.

As of CL 773962, JSONv2: true became the baseline. The current trajectory is that in Go 1.27 the aforementioned changes are the default, making it so explicitly setting GOEXPERIMENT=nojsonv2 means:

"The older v1-only implementation [...] can be enabled using GOEXPERIMENT=nojsonv2."

That aspect of GOEXPERIMENT=nojsonv2 seems useful to make it possible to start using the new Go 1.27 toolchain sooner and have temporary fine-grained control over its new behaviors. If someone needs to access the "older v1-only implementation" for some time, they can stay with a 1.27 toolchain and migrate any code that needs attention gradually. (This is in line with https://go.dev/blog/compat.)

As currently implemented at tip, GOEXPERIMENT=nojsonv2 can only be used when the package one is building and all of its dependencies (both direct and indirect) don't import encoding/json/v2 nor encoding/json/jsontext. Otherwise it will fail to compile. This is fine, but may not be as useful of a behavior for Go 1.27+; it just happened to be the natural outcome of making the jsonv2 baseline toggle a very small internal change.

So it might be worth considering removing the "//go:build goexperiment.jsonv2" build constraints in v2 and jsontext packages for Go 1.27, reducing the scope of GOEXPERIMENT=nojsonv2 to be about making the "older v1-only implementation" change only, and not be about making v2 and jsontext packages unavailable to be built. It could also be renamed/flipped to be "GOEXPERIMENT=jsonv1impl" if desired, though that's a bigger change that'd need updating some docs and touching every go:build constraint instead of only deleting some. Filing this issue to consider this.

CC @dsnet, @prattmic.

Metadata

Metadata

Assignees

No one assigned

    Labels

    NeedsInvestigationSomeone must examine and confirm this is a valid issue and not a duplicate of an existing one.

    Type

    No type
    No fields configured for issues without a type.

    Projects

    Status
    Done

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions