Go Benchmark
JSON Encoding Libraries
encoding/json vs goccy/go-json vs json-iterator vs sonic.
encoding/json is famously one of the slower parts of the Go standard library, and a whole ecosystem of drop-in replacements has grown around it. This benchmark marshals and unmarshals a typical small API struct with the standard library, github.com/goccy/go-json, github.com/json-iterator/go, and ByteDance's github.com/bytedance/sonic (JIT + SIMD accelerated). Unmarshal is where the standard library loses the most ground — its reflection-heavy decoder is several times slower than the alternatives. Before adding a dependency, remember the other side of the trade: encoding/json is maintained by the Go team, has no unsafe tricks, and its successor encoding/json/v2 (still experimental behind GOEXPERIMENT=jsonv2) closes much of this gap.
1 CPU
32 CPUs
github.com/goccy/go-json, an API-compatible replacement that compiles per-type opcode sequences instead of interpreting reflection on every call. Pure Go (no JIT or assembly), works on every platform, and typically the fastest of the pure-Go options — especially for decoding.
Sonic #
ByteDance's github.com/bytedance/sonic, which JIT-compiles codecs at runtime and uses SIMD instructions for scanning. Extremely fast, but the heavy machinery has costs: amd64/arm64 only, unsafe under the hood, and new Go versions need explicit support from the library before you can upgrade.
Json Iterator #
github.com/json-iterator/go with ConfigCompatibleWithStandardLibrary, an iterator-style decoder that was the go-to encoding/json replacement for years. Still noticeably faster than the standard library at decoding, but development has largely stalled and newer libraries have overtaken it.
The standard library's encoding/json. Marshalling uses cached reflection-based encoders and holds up reasonably well; unmarshalling walks the input with a reflection-driven decoder, which is where most of its reputation for slowness comes from. Zero dependencies, battle-tested, and the safe default.
Contributors