explaingit

bytedance/sonic

9,382GoAudience · developerComplexity · 2/5Setup · easy

TLDR

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.

Mindmap

mindmap
  root((sonic))
    What it does
      JSON encoding
      JSON decoding
      Partial field access
    Tech Stack
      Go
      JIT compilation
      SIMD instructions
    Use Cases
      High throughput APIs
      Partial JSON reads
      Unknown structures
    Performance
      Faster than stdlib
      JIT generated code
      CPU batch processing
    Audience
      Go developers
      Backend engineers
Click or tap to explore — scroll the page freely

Code map

Detail Auto

An interactive map of this repo's files and how they connect — its source is parsed live in your browser. Click Visualize to build it.

filefunction / class

Things people build with this

USE CASE 1

Speed up JSON serialization in a high-throughput Go API service by swapping in Sonic for encoding/json with minimal code changes

USE CASE 2

Read or modify a specific field deep inside a large JSON document without parsing the entire structure

USE CASE 3

Handle JSON data of unknown or variable structure at runtime without pre-defining Go structs

Tech stack

Go

Getting it running

Difficulty · easy Time to first run · 5min

Requires Go 1.18+ on Linux, macOS, or Windows with an AMD64 or ARM64 CPU, JIT and SIMD optimizations are CPU-architecture-specific.

License not specified in the explanation.

In plain English

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.

Copy-paste prompts

Prompt 1
Replace encoding/json with bytedance/sonic in my Go HTTP API server to speed up JSON marshaling, show me the import swap and any gotchas
Prompt 2
Use sonic's partial JSON parsing to extract just the user ID field from a large nested JSON response without unmarshaling the whole document
Prompt 3
Benchmark sonic against encoding/json in my Go service that processes high-volume webhook payloads to see the real-world speedup
Prompt 4
Set up sonic in a Go service that receives JSON with unpredictable structures and needs to handle it without predefined structs
Prompt 5
Migrate my Go app's JSON handling to sonic and validate correctness by running my existing test suite against both libraries
Open on GitHub → Explain another repo

← bytedance on gitmyhub — every repo by this author, as a profile.

Verify against the repo before relying on details.