finds.dev← search

// the find

tidwall/gjson

★ 15,546 · Go · MIT · updated May 2026

Get JSON values quickly - JSON parser for Go

GJSON is a Go library for extracting values from JSON by path expression without unmarshalling the whole document. It targets the common case where you know which fields you need and don't want to pay the cost of a full decode into a struct or map. At 202 ns/op with zero allocations for a simple get, it's meaningfully faster than encoding/json for read-only access patterns.

Zero-allocation path gets are the headline number and they hold up — the implementation walks the raw JSON bytes rather than building an intermediate tree. The path syntax covers genuinely useful territory: array queries with comparison operators, multipath extraction, and JSON Lines support, without becoming a full query language. Custom modifiers let you pipe results through your own transform functions, which is a clean extension point that doesn't require forking the library. The Result type exposes the raw byte index into the original document, so you can do zero-copy sub-slicing when working with []byte — that's a thoughtful detail most JSON libs skip.

GJSON is read-only; writing or patching JSON requires SJSON, a separate library. That split is fine architecturally but means two imports and two mental models for any flow that reads then writes. The query syntax for filtering arrays (#(key=="value")) is its own mini-language with its own edge cases — it's not JSONPath or JMESPath, so existing tooling and familiarity don't carry over. Input validation is the caller's problem: malformed JSON won't panic, but the docs are honest that it may return garbage, so every call site that touches untrusted input needs a gjson.Valid() guard first, which is easy to forget. The library is single-threaded in the sense that AddModifier writes to a global map with no documented concurrency guarantees — registering custom modifiers at init time is fine, but anything dynamic will need external locking.

View on GitHub →

// want more like this?

We dig through GitHub every week and send a few repos picked for what you actually care about — each with an honest take like this one.

Get finds in your inbox → Search again →