GithubHelp home page GithubHelp logo

sanity-io / groq-cli Goto Github PK

View Code? Open in Web Editor NEW
191.0 6.0 11.0 50 KB

Run GROQ in your command line

Home Page: https://groq.dev

License: MIT License

JavaScript 100.00%
groq json json-api json-parser query-language sanity-io

groq-cli's Introduction

groq-cli

Currently in alpha.

Easy wrangling of JSON documents with GROQ in the command line.

The CLI tool consumes both JSON and NDJSON) documents. You can pass in data from a local file, or from piping to standard input.

Read the announcement blog post, and the getting started guide.

Install

npm install --global groq-cli

Requirements

This CLI requires Node v10 or later.

Usage

$ groq --help
  Run GROQ in the command line

  Usage
    $ groq '*[<filter>]{<projection>}'
    # Remember to alternate quotation marks inside of the query

  Options
    -i, --input   One of: ndjson, json, null
    -o, --output  One of: ndjson, json, pretty
    -p, --pretty  Shortcut for --output=pretty
    -n, --ndjson  Shortcut for --input=ndjson --output=ndjson

  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 — a lightweight and flexible command-line JSON processor.
  • gron - Make JSON greppable!

License

MIT – Copyright 2019–present Sanity Inc.

groq-cli's People

Contributors

judofyr avatar kmelve avatar sgulseth avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

groq-cli's Issues

'--primary' flag no longer works

At https://www.sanity.io/blog/we-re-open-sourcing-groq-a-query-language-for-json-documents we see the query

$ groq '*[gender == "female" && "physics" in prizes[].category]{firstname, surname}' \
  --url http://api.nobelprize.org/v1/laureate.json \
  --pretty --primary laureates

resulting in

[
    {
      "firstname": "Marie",
      "surname": "Curie, née Sklodowska"
    },
    {
      "firstname": "Maria",
      "surname": "Goeppert Mayer"
    },
    {
      "firstname": "Donna",
      "surname": "Strickland"
    }
  ]

but today it prints null.

It appears that --primary is no longer there, and that that is the culprit. I say that because the query works as expected when we use jq instead of groq's --primary flag:

$ curl -s http://api.nobelprize.org/v1/laureate.json | jq .laureates | groq '*[gender == "female" && "physics" in prizes[].category]{firstname, surname}' --pretty

support for interactive mode

Would be nice to be able to just pass in a filename and enter a REPL mode to experiment with the syntax fast.

Possible memory leak

Seeing the below warning.

(node:27236) MaxListenersExceededWarning: Possible EventEmitter memory leak detected. 11 end listeners added. Use emitter.setMaxListeners() to inc
rease limit
[...]
irena $ wc -l migration/ndjson/employees.ndjson 
     343 migration/ndjson/employees.ndjson
irena $ du -sh !$
du -sh migration/ndjson/employees.ndjson
1.1M    migration/ndjson/employees.ndjson
irena $ cat migration/ndjson/employees.ndjson | groq --input ndjson '*[published==true]{name}'

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.