LinuxCommandLibrary
GitHubF-DroidGoogle Play Store

gojq

Pure Go implementation of jq JSON processor

TLDR

Pretty print JSON
$ cat [file.json] | gojq .
copy
Extract a field
$ cat [file.json] | gojq '.[field]'
copy
Filter array elements
$ cat [file.json] | gojq '.[] | select(.active == true)'
copy
Map and transform
$ cat [file.json] | gojq '[.[] | {name: .title, id: .uuid}]'
copy
Read from file directly
$ gojq '.users[]' [file.json]
copy
Process YAML input
$ gojq --yaml-input '.spec.containers[]' [deployment.yaml]
copy
Output as YAML
$ gojq --yaml-output '.data' [file.json]
copy
Use variables
$ gojq --arg name "[value]" '.items[] | select(.name == $name)' [file.json]
copy

SYNOPSIS

gojq [options] filter [file...]

DESCRIPTION

gojq is a pure Go implementation of jq, the JSON processor. It provides the same query language for filtering, transforming, and extracting data from JSON, with additional native YAML support.The filter language uses | for pipelines, . for field access, [] for iteration, and select() for filtering. Complex transformations combine these with object construction, array slicing, and built-in functions.YAML input and output make gojq particularly useful for Kubernetes and other YAML-heavy workflows. Variables with --arg enable parameterized queries for scripting.

PARAMETERS

-r, --raw-output

Output strings without JSON quotes.
-c, --compact-output
Compact output instead of pretty-printed.
-n, --null-input
Don't read input; useful with --argjson.
-e, --exit-status
Set exit code based on output.
-s, --slurp
Read all inputs into array.
-S, --sort-keys
Sort object keys in output.
-C, --color-output
Force colored output.
-M, --monochrome-output
Disable colored output.
--tab
Use tabs for indentation.
--indent n
Set indentation level.
--yaml-input
Parse input as YAML.
--yaml-output
Output as YAML instead of JSON.
--arg name value
Set variable to string value.
--argjson name json
Set variable to JSON value.
--slurpfile name file
Set variable to file contents as array.
--rawfile name file
Set variable to raw file contents.
-f, --from-file file
Read filter from file.
-L path
Add directory to module search path.

INSTALL

sudo apt install gojq
copy
sudo dnf install gojq
copy
sudo apk add gojq
copy
sudo zypper install gojq
copy
brew install gojq
copy
nix profile install nixpkgs#gojq
copy

CAVEATS

Some advanced jq features have minor behavioral differences. Performance may differ from C jq on very large files. Module paths are searched differently than jq. SQL-style operators are not implemented.

HISTORY

gojq was created by itchyny and first released around 2019. It was developed to provide jq functionality in a single Go binary without C dependencies. YAML support was added as a distinguishing feature. The project maintains close compatibility with jq while serving as a library for Go applications needing JSON transformation.

SEE ALSO

jq(1), yq(1), jless(1), fx(1)

RESOURCES

Braincup
Open source brain training for math, memory and focus
Braincup mini-games
41 mini-games · Apache-2.0
No ads · No tracking
Play in browser
Download Braincup on the App StoreGet Braincup on Google PlayGet Braincup on F-Droid
276 stars
From the maker of Linux Command Library
Copied to clipboard
Braincup
Open source brain training for math, memory and focus. 41 mini-games, from mental arithmetic to Sudoku, N-Back and Solo Chess.
Apache-2.0 licensed · No ads · No tracking · No account
From the maker of Linux Command Library
Download Braincup on the App StoreGet Braincup on Google PlayGet Braincup on F-Droid