The Go team has announced that the encoding/json/v2 and encoding/json/jsontext packages are now stable and will be generally available in Go 1.27.

JSON is the most widely used data format on the internet, and Go programs read and write it constantly. The standard library has supported JSON for well over a decade, but the Go team says the existing encoding/json package has accumulated a number of shortcomings. Some of its default behaviors are considered risky: it accepts invalid UTF-8 and objects with duplicate member names, and it matches object member names to struct fields case-insensitively. Other issues involve how nil slices and maps are marshaled, inconsistent handling of pointer-receiver methods, and an API that makes options hard to apply everywhere.
Performance is also a concern. The MarshalJSON and UnmarshalJSON interface methods force extra allocations and repeated parsing, and the package buffers whole values in memory rather than streaming them. Because these limits follow from the existing public API, the team concluded that they could not be fixed within the Go 1 compatibility promise, so they created a new major version instead.
The new design splits JSON handling into two layers. The jsontext package deals only with syntax and does not use reflection, offering streaming encoders and decoders that work on values and tokens. Built on top of it, encoding/json/v2 handles the mapping between JSON and Go values, accepts options as a first-class argument, and adds interfaces such as MarshalerTo and UnmarshalerFrom that support streaming. The team says code using v1 should mostly work unchanged when migrated to v2.
Source: go.dev







