Go JSON v2 Migration: What Breaks in Go 1.27
Go 1.27 introduced the encoding/json/v2 package in the standard library. Users may not notice this change as their output remains the same, but errors can differ and some behaviors have changed. Nil slices and maps are now marshaled as [] and {}, which is more compatible with JavaScript clients. OmitEmpty (omitempty) now omits fields only if they would encode as JSON null, empty, or {}.
Case-insensitive field matching is removed, and duplicate keys are rejected unless explicitly allowed. Invalid UTF-8 is treated as an error in v2. Go 1.27.1, the current point release as of 2026-10-03, supports both the old and new implementations. To switch to the new implementation, upgrade to Go 1.27 and run tests. When migrating, pay attention to error messages, as they may differ.
Most differences can be attributed to types, so the same struct encodes identically with either package. The new implementation also introduces options like json.RejectUnknownMembers(true) that are not available in the old version.
Written by urgent.news from Lobsters's reporting — not their text. Machine-written — may contain errors; check the original before relying on it.