
GJSON
A fast Go library for pulling values out of JSON using simple dot-style paths.
- Stars
- 15.6k
- Forks
- 2.2k
- Licence
- MIT
- Language
- Go
- Last update
- 1 months ago
- Type
- Library
What it is
GJSON is a Go package that reads values from a JSON document using short path strings such as "name.last" or "age". You give it the JSON text and a path, and it returns the matching value without you having to define structs or fully parse the document. It also supports array queries, iteration, and modifier functions for simple transformations.
- Read a nested field such as name.last from an API response in one call
- Count array elements with a path like children.#
- Find the first or all array items matching a condition, such as friends.#(age>45)#.last
- Reverse or reformat parts of a JSON document using built-in modifiers like @reverse or @pretty
Great for
- Go developers who need a few fields from a JSON response without writing struct definitions
- Services that read large JSON payloads and want to avoid full unmarshalling for simple lookups
- Developers who want to filter array elements with short query expressions
- Projects that process JSON Lines input
Not ideal for
- Projects that need to modify JSON; the README points to the separate SJSON project for that
- Non-Go projects; the README mentions Python and Rust ports maintained separately, not this Go package
- Anyone needing full schema validation or typed mapping of whole documents, since this focuses on path-based lookups
How to get it
- 1
Install with a package manager
You'll need: Go
Install the library
go get -u github.com/tidwall/gjson - 2
Run it
- Install Go and run the go get command shown in the README
- Import github.com/tidwall/gjson in a Go file
- Call gjson.Get(json, "name.last") with a JSON string and a path
- Call .String() on the result to print the value
- 3
Get the most out of it
- Use GetBytes when your JSON is already a byte slice
- Use the #(...)# query syntax to collect all matching array items
- Chain paths with the pipe character, for example children|@reverse|0
- Pass options to @pretty, such as sortKeys, to format output
- Register custom modifiers with gjson.AddModifier for project-specific transforms
Downloads
Strengths
- Simple one-line lookups using dot-notation paths, as shown in the README examples
- Supports 64-bit integer reads through Int() and Uint()
- Extensible with custom modifiers via AddModifier
Trade-offs
- The README's performance claims are linked but not verified here; treat speed as unconfirmed by this review
- Query syntax and modifiers have their own learning curve, and the full details live in SYNTAX.md
- Older bracket query syntax #[...] is deprecated and only kept until the next major release
How it compares
| Project | Stars | Type | Level | Updated | Best for |
|---|---|---|---|---|---|
| gjson (this) | 15.6k | Library | beginner | 1 months ago | Go developers who need a few fields from a JSON response without writing struct definitions |
| go | 13.9k | Library | beginner | 2.4 years ago | Go developers who parse or produce large amounts of JSON and want to test a faster option |
| json | 50.8k | Library | beginner | 4 days ago | C++ developers who need to read or write JSON in an application |
| SwiftyJSON | 22.9k | Library | beginner | 3 months ago | Swift developers building iOS, macOS, tvOS or watchOS apps that read JSON from web APIs |
| zerolog | 12.5k | Library | beginner | 23 days ago | Go developers who want machine-readable JSON logs |
| yq | 16.2k | CLI | beginner | 8 days ago | Developers who regularly edit YAML config files in scripts or CI pipelines |
Stats synced from GitHub. The assessment above was drafted with AI from the project's README on 2026-10-29 and may miss recent changes — check the README before relying on a command. MIT licence: free to use, modify and distribute, including commercially, as long as you keep the copyright notice.