A new Go API for JSON
Go has officially released encoding/json/v2 and encoding/json/jsontext in Go 1.27, addressing major performance bottlenecks, standard compliance issues, and API flaws from v1.
read it It details the architectural split between syntax and semantics, performance gains up to 10x, and how backward compatibility with v1 is maintained.
summary
The Go team has stabilized encoding/json/v2 and jsontext to fix long-standing behavioral flaws, security concerns, and performance limitations in the original standard library package. By decoupling syntactic processing from semantic mapping, the new API introduces streaming support, native options, and significant unmarshaling speedups of up to 10x. Crucially, v1 is implemented under the hood using v2 options, ensuring a smooth, gradual ecosystem migration without forcing breaking changes on existing dependencies.
key points
- The new jsontext package handles low-level syntax without reflection, enabling true streaming and allocation-free token operations.
- Behavior fixes include strict adherence to RFC 8259 regarding invalid UTF-8, rejection of duplicate object keys for security, and case-sensitive struct matching.
- Unmarshaling performance is up to 10x faster, especially when custom types implement the new streaming UnmarshalJSONFrom interface.
who should read it
Go developers and backend engineers maintaining performance-critical applications that parse or generate large volumes of JSON.
discussion positive
consensus
Commenters generally express relief and enthusiasm that these long-standing pain points are finally resolved, though some question why it took six years to land.
pushback
A minority of commenters debate language velocity, design choices, or potential edge cases with the new default behaviors like marshaling nil slices.
The fact that this took 6 years to land stood out to me.
I'm not entirely surprised, and I'm glad the Go team is carefully considering their interfaces before launching. But 6 years seems like a lot of work to land a JSON API.
It highlights the remarkably long six-year development timeline for a JSON library update, prompting broader discussions on Go team feature velocity.
Generated by an LLM from the article and thread. Check the sources before relying on it.