A new Go API for JSON
The Go team has released encoding/json/v2 and encoding/json/jsontext, a new stable JSON API in Go 1.27 designed to address behavioral flaws and performance limitations in the original package. The new v2 packages separate syntax from semantics, introduce streaming-oriented JSON encoding and decoding interfaces, reject invalid UTF-8 and duplicate object keys by default, and provide options-based configuration. Despite these structural improvements and up to 10x faster unmarshaling performance, v1 is implemented under the hood in terms of v2 to ensure backward compatibility and smooth ecosystem migration. Open article →
Notable comments
Reception is broadly positive (especially for safer defaults and performance), but a recurring theme is migration friction/stdlib API design details, plus skepticism about whether “broken defaults” will need another round of fixes later.
HN · txomon First-hand: they used `jsontext` in production to build a high-performance JSON parser with precise, category-specific error reporting; they “would definitely recommend jsontext as a parser for anything non-straightforward.”
HN · SkiFire13 Sharp critique: “nil slices and maps are marshaled as an empty JSON array or object by default” is framed as a likely backward/behavior bite that will “eventually need to be fixed in a v3.”
HN · CamouflagedKiwi Practical migration pain: they like `encoding/json/v2` but flag the missing `MarshalIndent`, saying the equivalent is “super complicated and non-obvious,” making quick readable dumps harder to migrate.