sonic
A blazingly fast JSON serializing & deserializing library
A Go JSON library from ByteDance that encodes and decodes JSON several times faster than the standard library, using JIT compilation and SIMD CPU instructions, a near-drop-in replacement for encoding/json.
Sonic is a Go library that converts data between JSON text and Go program objects, doing it much faster than the standard library that ships with Go. JSON is everywhere in software: APIs send it, config files use it, and services exchange it constantly. Converting JSON to usable data and back is something most programs do thousands of times, so speed matters.
The library achieves its speed through two lower-level techniques. One is JIT compilation, where it generates optimized machine code at runtime tailored to the exact data structures your program uses. The other is SIMD, a CPU feature that processes multiple pieces of data in a single instruction, like sorting a stack of cards all at once rather than one at a time. Together these let Sonic process JSON several times faster than alternatives.
For a Go developer, switching to Sonic typically requires changing just a few lines of import code, since it is designed as a drop-in replacement for the standard library's JSON package. It also offers additional features beyond basic encoding and decoding, including tools to read or modify specific fields inside a JSON document without parsing the whole thing, and a way to work with JSON data whose structure you do not know in advance.
ByteDance, the company behind TikTok, created and open-sourced this library. The benchmarks in the README show it outperforming other popular Go JSON libraries across a range of document sizes and usage patterns. It runs on Linux, macOS, and Windows, and supports both AMD64 and ARM64 processors. Go version 1.18 or newer is required.
Where it fits
- Speed up JSON serialization in a high-throughput Go API service by swapping in Sonic for encoding/json with minimal code changes
- Read or modify a specific field deep inside a large JSON document without parsing the entire structure
- Handle JSON data of unknown or variable structure at runtime without pre-defining Go structs