| A new Go API for JSON(go.dev) | |
| 388 points by olexsmir 7 days ago | 201 comments | |
tl;dr: Go 1.27 ships stable `encoding/json/v2` and `encoding/json/jsontext` packages, addressing long-standing issues in the original JSON library: invalid UTF-8 acceptance, duplicate object keys, case-insensitive field matching, nil slice/map handling, and performance limitations in `MarshalJSON`/`UnmarshalJSON`. The new API separates syntax (jsontext) from semantics (json/v2), supports streaming via new `MarshalerTo`/`UnmarshalerFrom` interfaces, and accepts options as first-class arguments, with unmarshal benchmarks up to 10x faster. v1 is now implemented on top of v2, ensuring interoperability and enabling gradual migration via opt-in behavior flags. | |
HN Discussion:
| |