Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/sanity-io/groq-cli
Run GROQ in your command line
https://github.com/sanity-io/groq-cli
groq json json-api json-parser query-language sanity-io
Last synced: about 1 month ago
JSON representation
Run GROQ in your command line
- Host: GitHub
- URL: https://github.com/sanity-io/groq-cli
- Owner: sanity-io
- License: mit
- Created: 2019-07-02T09:47:39.000Z (over 5 years ago)
- Default Branch: main
- Last Pushed: 2024-07-25T19:00:05.000Z (5 months ago)
- Last Synced: 2024-10-21T16:45:57.912Z (about 2 months ago)
- Topics: groq, json, json-api, json-parser, query-language, sanity-io
- Language: JavaScript
- Homepage: https://groq.dev
- Size: 339 KB
- Stars: 201
- Watchers: 11
- Forks: 15
- Open Issues: 5
-
Metadata Files:
- Readme: readme.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
- awesome-cli-apps - GROQ
- fucking-awesome-cli-apps - GROQ
- jimsghstars - sanity-io/groq-cli - Run GROQ in your command line (JavaScript)
- my-awesome-list - groq-cli - io | 205 | (JavaScript)
README
# groq-cli
_Currently in alpha._
> Easy wrangling of JSON documents with [GROQ](https://github.com/sanity-io/groq) in the command line.
The CLI tool consumes both JSON and [NDJSON](https://github.com/ndjson/ndjson-spec)) documents. You can pass in data from a local file, or from piping to standard input.
Read the [announcement blog post](https://www.sanity.io/blog/we-re-open-sourcing-groq-a-query-language-for-json-documents), and the [getting started guide](https://www.sanity.io/docs/data-store/how-queries-work).
## Install
```bash
npm install --global groq-cli
```## Requirements
This CLI requires Node v18 or later.
## Usage
```bash
$ groq --help
Run GROQ in the command lineUsage
$ groq '*[]{}'
# Remember to alternate quotation marks inside of the queryOptions
-i, --input One of: ndjson, json, null
-o, --output One of: ndjson, json, pretty, type-nodes
-p, --pretty Shortcut for --output=pretty
-n, --ndjson Shortcut for --input=ndjson --output=ndjson
-s, --schema Path to a schema file, only required when output is set to "type-nodes"Input formats
json Reads a JSON object from stdin.
ndjson Reads a JSON stream from stdin.
null Reads nothing.Output formats
json Formats the output as JSON.
pretty Formats the output as pretty JSON.
ndjson Streams the result as NDJSON.Examples
# Query data in a file
$ cat blog.json | groq 'count(posts)'# Query data in a NDJSON file
$ cat blog.ndjson | groq --input ndjson '*[_type == "post"]{title}'# Query JSON data from an URL
$ curl -s https://jsonplaceholder.typicode.com/todos | groq --pretty '*[completed == false]{title}'
```## Similar tools
GROQ-cli isn't the only tool to work with JSON data in the command line. If it doesn't do exactly what you need, you can check out these other tools that might help you:
- [jq](https://stedolan.github.io/jq/) — a lightweight and flexible command-line JSON processor.
- [gron](https://github.com/tomnomnom/gron) - Make JSON greppable!## License
MIT – Copyright 2019–present Sanity Inc.