https://github.com/hherman1/gq Skip to content Sign up * Product + Features + Mobile + Actions + Codespaces + Packages + Security + Code review + Issues + Integrations + GitHub Sponsors + Customer stories * Team * Enterprise * Explore + Explore GitHub + Learn and contribute + Topics + Collections + Trending + Learning Lab + Open source guides + Connect with others + The ReadME Project + Events + Community forum + GitHub Education + GitHub Stars program * Marketplace * Pricing + Plans + Compare plans + Contact Sales + Education [ ] * # In this repository All GitHub | Jump to | * No suggested jump to results * # In this repository All GitHub | Jump to | * # In this user All GitHub | Jump to | * # In this repository All GitHub | Jump to | Sign in Sign up {{ message }} hherman1 / gq Public * Notifications * Fork 1 * Star 96 jq but using go instead MIT License 96 stars 1 fork Star Notifications * Code * Issues 0 * Pull requests 0 * Actions * Projects 0 * Wiki * Security * Insights More * Code * Issues * Pull requests * Actions * Projects * Wiki * Security * Insights This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository. main Switch branches/tags [ ] Branches Tags Could not load branches Nothing to show {{ refName }} default View all branches Could not load tags Nothing to show {{ refName }} default View all tags 3 branches 4 tags Code Latest commit @hherman1 hherman1 add help ... c7e8497 Apr 27, 2022 add help c7e8497 Git stats * 14 commits Files Permalink Failed to load latest commit information. Type Name Latest commit message Commit time gq fix G for singletons Apr 27, 2022 .gitignore Add dist script Apr 27, 2022 LICENSE Create LICENSE Apr 27, 2022 README.md Update README.md Apr 27, 2022 dist.sh Add dist script Apr 27, 2022 go.mod use interpreter instead for better perf Apr 27, 2022 go.sum use interpreter instead for better perf Apr 27, 2022 main.go add help Apr 27, 2022 program.go.tmpl use interpreter instead for better perf Apr 27, 2022 View code gq Install Usage Examples Why? How's it work? This tool sucks. README.md GoDoc gq jq but using go instead. Install go install github.com/hherman1/gq@latest Or download the binaries here Usage Pipe some input into gq and pass in a block of go code as the argument. The variable j is set to the passed in JSON and printed at the end of the function, so manipulate it (e.g below) in order to change the output. The gq library is inlined in the program, and described in detail in the API reference above. Examples Accesses $ echo '{"weird": ["nested", {"complex": "structure"}]}' | gq 'j.G("weird").I(1).G("complex")' "structure" Filters $ echo '["list", "of", "mostly", "uninterseting", "good/strings", "good/welp"]' | gq 'j.Filter(func(n *Node) bool { return strings.Contains(n.String(), "good/") })' [ "good/strings", "good/welp" ] Maps $ echo '[1, 2, 3, 4]' | gq 'j.Map(func(n *Node) *Node {n.val = n.Int() + 50 / 2; return n})' [ 26, 27, 28, 29 ] Why? jq is hard to use. There are alternatives like fq and zq, but they still make you learn a new programming language. Im tired of learning new programming languages. gq is not optimized for speed, flexibility or beauty. gq is optimized for minimal learning/quick usage. gq understands that you don't use it constantly, you use it once a month and then forget about it. So when you come back to it, gq will be easy to relearn. Just use the builtin library just like you would any other go project and you're done. No unfamiliar syntax or operations, or surprising limits. Thats it. How's it work? Speaking of surprising limits, gq runs your code in the yaegi go interpreter. This means that it runs quickly for small inputs/ programs (the alternative was go run, which is... not quite as quick). However, it also means its not the fastest *q out there, and further it means that you might run into quirks with yaegi interpretation limitations. Seems to work pretty well so far though. This tool sucks. Yea, well, I built it last night, so, yea it kinda sucks. But please file issues! Or submit PRs! Maybe this will turn into something useful? At least maybe it will inspire some conversation. I think it needs a lot of refinement still, in short. About jq but using go instead Resources Readme License MIT License Stars 96 stars Watchers 1 watching Forks 1 fork Releases 2 v0.0.3: Add help Latest Apr 27, 2022 + 1 release Packages 0 No packages published Languages * Go 96.7% * Shell 3.3% * (c) 2022 GitHub, Inc. * Terms * Privacy * Security * Status * Docs * Contact GitHub * Pricing * API * Training * Blog * About You can't perform that action at this time. You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.