explaingit

goccy/go-json

Analysis updated 2026-07-03

3,664GoAudience · developerComplexity · 2/5Setup · easy

TLDR

A faster drop-in replacement for Go's standard JSON library that speeds up encoding and decoding with a single import change, while adding context support and dynamic field filtering.

Mindmap

mindmap
  root((repo))
    What it does
      JSON encoding
      JSON decoding
      Drop-in replacement
    Why Faster
      Buffer reuse
      Pre-built type code
      No runtime reflection
    Extra Features
      Context support
      Dynamic field filter
      Syntax coloring
    Tech Stack
      Go
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

What do people build with it?

USE CASE 1

Speed up JSON encoding and decoding in an existing Go service by swapping the standard library import for go-json.

USE CASE 2

Pass a context value through custom JSON marshal and unmarshal methods for distributed tracing or cancellation.

USE CASE 3

Dynamically exclude certain struct fields from JSON output without losing Go type safety.

What is it built with?

Go

How does it compare?

goccy/go-jsonchristianselig/apollo-backenddoitintl/kube-no-trouble
Stars3,6643,6633,662
LanguageGoGoGo
Setup difficultyeasyhardeasy
Complexity2/53/52/5
Audiencedeveloperdeveloperops devops

Figures from each repo's GitHub metadata at analysis time.

How do you get it running?

Difficulty · easy Time to first run · 5min

In plain English

go-json is a Go library for converting data to and from JSON format. It is designed as a drop-in replacement for the standard library's built-in encoding/json package, meaning you can switch to it by changing a single import line and the rest of your code stays the same. The main reason to use it over the standard library is speed. The README includes benchmark charts showing it is faster than several comparable Go JSON libraries for both encoding (converting Go data to JSON text) and decoding (converting JSON text back into Go data). It achieves this through a set of internal optimizations: reusing memory buffers across calls rather than allocating new ones each time, pre-building type-specific processing functions to avoid slow reflection at runtime, and generating optimized code paths at program startup rather than inspecting types on every call. Beyond raw speed, the library adds a few features not found in the standard package. You can pass a context value through to custom marshal and unmarshal methods (useful for things like tracing or cancellation). You can dynamically filter which fields of a struct get included in JSON output without losing type safety. Encoded output can also be syntax-colored for display purposes. Installation is one line using the standard Go module tool. Switching an existing project over requires only updating the import path. The library maintains full compatibility with the standard encoding/json interface, which several other faster JSON libraries sacrifice in exchange for their speed gains. The README notes a fuzzing test repository exists to help catch edge cases and bugs.

Copy-paste prompts

Prompt 1
Show me how to replace encoding/json with go-json in my Go HTTP API server. What exactly changes in the import and usage?
Prompt 2
How do I use go-json's context-aware marshaling to pass a trace ID through to a custom MarshalJSON method?
Prompt 3
I want to dynamically exclude certain fields from a Go struct when marshaling to JSON based on a runtime condition. Show me how with go-json's field filter.
Prompt 4
Write a Go benchmark test comparing encoding/json and go-json on a struct with 15 fields to measure the throughput difference.
Prompt 5
How does go-json maintain compatibility with encoding/json interfaces while being faster?

Frequently asked questions

What is go-json?

A faster drop-in replacement for Go's standard JSON library that speeds up encoding and decoding with a single import change, while adding context support and dynamic field filtering.

What language is go-json written in?

Mainly Go. The stack also includes Go.

How hard is go-json to set up?

Setup difficulty is rated easy, with roughly 5min to a first successful run.

Who is go-json for?

Mainly developer.

Open on GitHub → Explain another repo

This repo across BitVibe Labs

Scan in gitsafehub Deploy in gitdeployhub goccy on gitmyhub

Verify against the repo before relying on details.