Read specific fields from a JSON API response in Go without defining matching data structs
Filter and query JSON arrays using comparison operators like greater-than, less-than, or pattern matching
Build Go scripts, CLI tools, or log processors that need to dig into unfamiliar JSON payloads quickly
Chain path queries and transformations like reverse, pretty-print, or key extraction in a single expression
GJSON is a small library for the Go programming language that pulls specific values out of a JSON document quickly and with very little code. JSON is the format most web APIs use to send data, a nested set of names, values, and lists, and normally you have to define matching data structures in Go just to read one field. GJSON skips that step: you hand it a JSON string and a path that describes where in the document the value lives, and it returns the value directly. Paths use a simple dot syntax that looks a lot like spreadsheet cell references: "name.last" reaches into an object, "children.1" gets the second item in an array, and "children.#" gives the number of items. The "#" character also opens up array queries with comparison operators (equals, greater-than, less-than, "like" pattern matching) so you can ask for things like the last name of every friend over 45. Wildcards (* and ?) let you match keys you only partly know. Results come back as a Result type that can be turned into the obvious Go types, a string, an integer, a float, a boolean, or even a time. Modifiers, written with an @ prefix, can transform the result mid-path, @reverse flips an array, @pretty and @ugly reformat the JSON, @keys and @values pull apart objects, and a pipe character chains them. You would use GJSON whenever you need to read a JSON response or file in Go without writing a struct for it: quick scripts, command-line tools, log processors, or for digging into unfamiliar payloads. A companion library called SJSON handles modifying JSON, and a command-line tool called JJ wraps the same engine. Ports also exist for Python and Rust. The full README is longer than what was provided.
← tidwall on gitmyhub — every repo by this author, as a profile.
Verify against the repo before relying on details.