A New Go API for JSON
Web page · https://go.dev/blog/jsonv2
First seen by Oriel on .
AI summary
The Go team introduces stable encoding/json/v2 and encoding/json/jsontext in Go 1.27, adding safer defaults, configurable APIs, streaming, and substantially faster unmarshaling while retaining v1 compatibility.
- encoding/json/v2 rejects invalid UTF-8 and duplicate object names, uses case-sensitive field matching, and marshals nil slices and maps as empty JSON collections.
- encoding/json/jsontext separates syntax from semantic processing with streaming Encoder and Decoder APIs for JSON values and allocation-free tokens.
- Marshal, Unmarshal, MarshalWrite, and UnmarshalRead accept options directly, while MarshalEncode and UnmarshalDecode operate on jsontext streams.
- New MarshalerTo and UnmarshalerFrom interfaces enable streaming custom serialization and propagate options; caller-specified Marshalers and Unmarshalers override type-defined behavior.
- Marshal performance is roughly comparable to v1, while Unmarshal benchmarks show improvements up to 10x; existing custom implementations must adopt streaming interfaces for greater gains.
#go #json #api design #streaming
Generated by gpt-5.6-sol. Check the original for details.
Metric trends
Last 30 days · Up to 120 recorded samples per source and metric, with reposts kept separate · First and latest retained
Points
Score reported by the source.
- Hacker News: 390, latest observation ; +363 over observed period since
- Lobsters: 39, latest observation ; +36 over observed period since
Comments
Comment count reported by the source.
- Hacker News: 211, latest observation ; +208 over observed period since
- Lobsters: 9, latest observation ; +8 over observed period since
Aliases
| Source | External ID | URL |
|---|---|---|
| Hacker News | 50369106 | https://go.dev/blog/jsonv2 Read discussion |
| Lobsters | gfm0xn | https://go.dev/blog/jsonv2 Read discussion |