GithubHelp home page GithubHelp logo

grontojq's Introduction

โœจ grontojq

๐Ÿ“ฆ Installation

go install github.com/bbbbbrie/grontojq@latest

That should put the grontojq executable in $GOBIN. If that's in $PATH, which grontojq should point you to it.

โ„น๏ธ How one might use grontojq

This is a Go tool that converts gron output into jq commands. I wrote this to solve a specific problem I had and as an excuse to write in Go again.

I typically use gron to help build the jq command I want to use for whatever I'm trying to do. While --ungron is nice, I don't want to have gron as a dependency in pipelines or other places where I'm making use of jq. I use gron to help build the jq commands. Once I have them, I use just jq for the actual parsing.

You can pipe the output of gron in to grontojq. Here's how I think grontojq is most useful:

First, you'll use gron cats.json to explore the JSON file you're interested in:

# gron cats.json
...
json.catDescriptions[10] = {};
json.catDescriptions[10].emoji = "๐Ÿ˜ฝ";
json.catDescriptions[10].word = "Charming";
json.catDescriptions[11] = {};
json.catDescriptions[11].emoji = "๐Ÿ˜ˆ";
json.catDescriptions[11].word = "Mischievous";

Next, you'll do something like gron cats.json | grep 11 | grep word to pick the exact line you're interested in:

# gron cats.json | grep 11 | grep word
json.catDescriptions[11].word = "Mischievous";

Then, you'll pass that output to grontojq:

# gron cats.json | grep 11 | grep word | grontojq
jq '.catDescriptions[11].word'

You can copy this from your terminal or use pbcopy or similar to copy it straight to your clipboard with something like gron cats.json | grep 11 | grep word | grontojq | pbcopy.

Finally, you'll take the output from grontojq and use it to parse the file more elegantly:

jq '.catDescriptions[11].word' cats.json

๐Ÿˆโ€โฌ› Why?

This makes it a tiny bit easier to go from gron output to jq filter -- especially if piping to something like grontojq is easy to add to your terminal muscle memory. I'd alias it to something like g2jq or similar to make that even easier.

grontojq's People

Contributors

bbbbbrie avatar

Watchers

 avatar  avatar

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.