GJSON is a Go package for reading values from JSON documents with one-line dot-path queries. It supports iteration, modifiers, array queries, and JSON Lines.
Overview
GJSON helps Go programs pull fields from JSON without unmarshaling entire documents into structs. The Get function takes a path in dot notation (for example name.last or nested array indexes) and returns a Result as soon as the value is found.
Path syntax covers wildcards, array length with #, filtered queries with comparison and pattern operators, escaped dots, and chained modifiers separated by pipes. Built-in modifiers include reverse, pretty print, flatten, keys, values, and dig-style search without a full path.
Results expose typed accessors for strings, numbers, booleans, and raw nested JSON. ForEach walks objects and arrays; GetBytes and index-based slicing aim to reduce allocations when working on byte slices. Parse plus Get offers the same lookups after a simple parse step.
The library also handles JSON Lines via a .. prefix and ForEachLines. Modifiers can be extended in user code. Implementations exist for Python and Rust under the same project family, and the JJ command-line tool is mentioned as a companion for shell use.
Key features
- Dot-notation path lookups
- Wildcard and query filters on arrays
- Modifier pipeline and custom modifiers
- ForEach over objects and arrays
- GetBytes for byte slice JSON
- JSON Lines iteration support
- 64-bit integer reads
- Exists checks without full parse
Use cases
- Read nested API fields in Go services
- Scan large JSON logs for one key
- Query array elements with predicates
- Walk JSON Lines files line by line
- Pretty or flatten JSON in pipelines