easyjson generates Go marshal and unmarshal code for structs so JSON encoding skips reflection at runtime, with optional snake_case names and interned strings.
Overview
easyjson targets Go projects that need faster JSON serialization than the standard encoding/json package. A generator inspects struct definitions and writes easyjson.go files with MarshalEasyJSON, UnmarshalEasyJSON, and standard json.Marshaler-compatible methods.
Developers run the easyjson tool against packages (structs marked with easyjson:json comments or all structs with -all). Generated code is meant to stay simple enough to tune by hand, with options for snake_case field names, build tags, omitempty defaults, and skipping selected types.
Runtime serialization uses buffer pooling, optional string interning and nocopy string fields, type wrappers in easyjson/opt, and custom omitempty via the Optional interface. An easyjsonnounsafe build tag disables unsafe pointer use for unmarshaling when required.
The project documents benchmarks against encoding/json, ffjson, go/codec, and ujson, and notes limitations such as case-sensitive keys, limited float precision, and no full JSON validation on parse skips.
Key features
- Struct JSON code generation
- Reflection-free marshal path
- Snake_case name option
- String interning tag support
- Allocator buffer pooling
- Optional type wrappers
- HTTP response writer helpers
- Compatible json.Marshaler output
Use cases
- High-throughput Go APIs
- Large JSON payload services
- Replacing encoding/json hot paths
- Generated serializers for DTOs
- Low-allocation JSON parsing