RC RANDOM CHAOS

Go 1.27: JSON v2 Addresses Long-Standing Issues

· via Hacker News

Original source

A new Go API for JSON

Hacker News →

Go’s JSON library has carried design limitations for 15+ years without a path to fix them due to backward compatibility constraints. Go 1.27 releases encoding/json/v2 and encoding/json/jsontext as stable alternatives. The original package has multiple correctness issues: silent acceptance of invalid UTF-8, tolerance for duplicate object keys (a documented attack vector in prior CVEs), unexpected case-insensitive field matching, and inconsistent interface method invocation. Beyond behavioral flaws, the API prevents configuration options from applying uniformly across all serialization functions and forces JSON to be parsed multiple times during unmarshaling.

Creating a separate v2 namespace allowed breaking changes necessary to restore interoperability. The foundation is encoding/json/jsontext, which separates syntactic operations (JSON parsing and generation) from semantic mapping between JSON and Go types. This architectural distinction eliminates v1’s inherent constraints: unnecessary allocations during marshaling, repeated parsing during unmarshaling, and quadratic performance when marshaling methods recursively invoke marshaling functions. The split provides both cleaner APIs and substantially better performance.

Read the full article

Continue reading at Hacker News →

This is an AI-generated summary. Read the original for the full story.