Skip to content
Pure Go implementation of jq
Go JSONiq Makefile
Branch: master
Clone or download
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
.github/workflows setup GitHub Actions Sep 27, 2019
_tools implement arbitrary precision integer calculation Aug 17, 2019
cli implement YAML output option Oct 2, 2019
cmd/gojq implement gojq cli tool Apr 11, 2019
.gitignore change executable output to the root directory of the repository Aug 3, 2019
CHANGELOG.md update CHANGELOG.md for v0.6.0 Aug 25, 2019
LICENSE init gojq Apr 11, 2019
Makefile rename builtin_gen.go builtin.go Aug 16, 2019
README.md setup GitHub Actions Sep 27, 2019
builtin.go implement repeat function Aug 17, 2019
builtin.jq implement repeat function Aug 17, 2019
clone.go implement delpaths function Jul 21, 2019
code.go implement debug function Jul 27, 2019
compare.go implement arbitrary precision integer calculation Aug 17, 2019
compiler.go optimize assignment where left hand side is constant keys indexing Aug 30, 2019
debug.go add more code information Jul 15, 2019
env.go remove paths struct Jul 28, 2019
error.go implement arbitrary precision integer calculation Aug 17, 2019
execute.go remove paths struct Jul 28, 2019
func.go refactor accept method of function Aug 18, 2019
go.mod implement YAML input option Oct 2, 2019
go.sum implement YAML input option Oct 2, 2019
iterator.go remove old recursive interpreter Jul 15, 2019
math.go support 32-bit architecture Aug 17, 2019
normalize.go implement arbitrary precision integer calculation Aug 17, 2019
operator.go support 32-bit architecture Aug 17, 2019
parser.go stricten token boundary of numbers Aug 25, 2019
query.go optimize assignment where left hand side is constant keys indexing Aug 30, 2019
release.go add more code information Jul 15, 2019
stack.go change scopes to forkable stack Jul 7, 2019

README.md

gojq CI Status

Pure Go implementation of jq.

Usage

 $ echo '{"foo": 128}' | gojq '.foo'
128
 $ echo '{"a": {"b": 42}}' | gojq '.a.b'
42
 $ echo '{"id": "sample", "10": {"b": 42}}' | gojq '{(.id): .["10"].b}'
{
  "sample": 42
}
 $ echo '[{"id":1},{"id":2},{"id":3}]' | gojq '.[] | .id'
1
2
3
 $ echo '{"a":1,"b":2}' | gojq '.a += 1 | .b *= 2'
{
  "a": 2,
  "b": 4
}
 $ echo '{"a":1} [2] 3' | gojq '. as {$a} ?// [$a] ?// $a | $a'
1
2
3
 $ echo '{"foo": 4722366482869645213696}' | gojq .foo
4722366482869645213696  # keeps the precision of number while jq does not
 $ gojq -n 'def fact($n): if $n < 1 then 1 else $n * fact($n - 1) end; fact(50)'
30414093201713378043612608166064768844377641568960512000000000000 # arbitrary-precision integer calculation

Nice error messages.

 $ echo '[1,2,3]' | gojq  '.foo & .bar'
gojq: invalid query: .foo & .bar
    .foo & .bar
         ^  unexpected token "&"
 $ echo '{"foo": { bar: [] } }' | gojq '.'
gojq: invalid json: <stdin>
    {"foo": { bar: [] } }
              ^  invalid character 'b' looking for beginning of object key string

Installation

Homebrew

brew install itchyny/tap/gojq

Build from source

go get -u github.com/itchyny/gojq/cmd/gojq

Difference to jq

  • gojq is purely implemented with Go language and is completely portable. jq depends on the C standard library so the availability of math functions depends on the library. jq also depends on the regular expression library and it makes build scripts complex.
  • gojq implements nice error messages for invalid query and JSON input. The error message of jq is sometimes difficult to tell where to fix the query.
  • gojq does not keep the order of object keys. I understand this might cause problems for some scripts but basically we should not rely on the order of object keys. I would implement when ordered map is implemented in the standard library of Go but I'm less motivated.
  • gojq supports arbitrary-precision integer calculation while jq does not. This is important to keeping the precision of numeric IDs or nanosecond values. You can use gojq to solve some mathematical problems which require big integers.

Bug Tracker

Report bug at Issues・itchyny/gojq - GitHub.

Author

itchyny (https://github.com/itchyny)

License

This software is released under the MIT License, see LICENSE.

You can’t perform that action at this time.