explaingit

tidwall/gjson

15,488GoAudience · developerComplexity · 2/5Setup · easy

TLDR

GJSON is a tiny Go library that extracts values from JSON documents using a simple dot-notation path, no structs needed, just pass the JSON and a path like 'name.last' and get the value back instantly.

Mindmap

mindmap
  root((GJSON))
    What it does
      JSON value extraction
      No struct needed
      Fast path queries
    Path syntax
      Dot notation
      Array indexing
      Wildcards
    Query features
      Comparison filters
      Array queries
      Chained modifiers
    Ecosystem
      SJSON for writes
      JJ CLI tool
      Python and Rust ports
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

Read specific fields from a JSON API response in Go without defining matching data structs

USE CASE 2

Filter and query JSON arrays using comparison operators like greater-than, less-than, or pattern matching

USE CASE 3

Build Go scripts, CLI tools, or log processors that need to dig into unfamiliar JSON payloads quickly

USE CASE 4

Chain path queries and transformations like reverse, pretty-print, or key extraction in a single expression

Tech stack

Go

Getting it running

Difficulty · easy Time to first run · 5min

In plain English

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.

Copy-paste prompts

Prompt 1
I have a JSON API response and I want to pull out the email of every user where age is greater than 30. Write the GJSON path expression and the Go code to run it.
Prompt 2
I need to get the third item from a nested JSON array using GJSON. Show me the path syntax for index-based access and wildcard matching.
Prompt 3
How do I use GJSON modifiers like @reverse and @pretty in a chained path expression? Show a real example with input JSON and expected output.
Prompt 4
I want to parse a large JSON log file in Go and extract specific fields without unmarshaling the whole thing. How do I use GJSON efficiently for this use case?
Open on GitHub → Explain another repo

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

Verify against the repo before relying on details.