npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

gron

v4.4.0

Published

<div align="center"> <br><p><strong>gron</strong> - Make JSON greppable!.</p> </div>

Downloads

52

Readme

=========================================

Deps NPM version

available-for-advisory extra

Make JSON greppable!

gron transforms JSON into discrete assignments to make it easier to grep for what you want and see the absolute 'path' to it. It eases the exploration of APIs that return large blobs of JSON but have terrible documentation.

▶ curl -s https://jsonplaceholder.typicode.com/users | gron | fgrep "company.name"
json[0].company.name = "Romaguera-Crona";
json[1].company.name = "Deckow-Crist";
json[2].company.name = "Romaguera-Jacobson";
json[3].company.name = "Robel-Corkery";
json[4].company.name = "Keebler LLC";
json[5].company.name = "Considine-Lockman";
json[6].company.name = "Johns Group";
json[7].company.name = "Abernathy Group";
json[8].company.name = "Yost and Sons";
json[9].company.name = "Hoeger LLC";

gron can work backwards too, enabling you to turn your filtered data back into JSON:

▶ curl -s https://jsonplaceholder.typicode.com/users | gron | fgrep "company.name" | ungron
[
  {
    "company": {
      "name": "Romaguera-Crona"
    }
  },
  {
    "company": {
      "name": "Deckow-Crist"
    }
  },
  ...
  ...

You like this?

If you like Gron, you will find jq.node awesome :rocket:! jq.node is JavaScript and Lodash in your shell!

Installation

Install with npm.

npm install -g gron

Usage

Get JSON from a file:

▶ cat testdata/two.json | gron
json = {};
json.name = "FGRibreau";
json.github = "https://github.com/fgribreau/";
json.likes = [];
json.likes[0] = "code";
json.likes[1] = "cheese";
json.likes[2] = "meat";
json.contact = {};
json.contact.email = "[email protected]";
json.contact.twitter = "@FGRibreau";

From a URL:

▶ curl -s http://headers.jsontest.com/ | gron
json = {};
json["X-Cloud-Trace-Context"] = "e76953d4e0a7a4c00a60d3d8329d0236/11387270255695883695";
json.Host = "headers.jsontest.com";
json["User-Agent"] = "curl/7.43.0";
json.Accept = "*/*";

Grep for something and easily see the path to it:

▶ cat testdata/two.json | gron | grep twitter
json.contact.twitter = "@FGRibreau";

gron makes diffing JSON easy too:

▶ diff <(cat testdata/two.json | gron) <(cat testdata/two-b.json | gron)
10c10
< json.contact.twitter = "@FGRibreau";
---
> json.contact.twitter = "@fgribreau";

The output of gron is valid JavaScript:

▶ cat testdata/two.json | gron > tmp.js
▶ echo "console.log(json);" >> tmp.js
▶ node tmp.js
{ name: 'FGRibreau',
  github: 'https://github.com/fgribreau/',
  likes: [ 'code', 'cheese', 'meat' ],
  contact: { email: '[email protected]', twitter: '@FGRibreau' } }

ungronning

gron can also turn its output back into JSON:

▶ cat testdata/two.json | gron | ungron
{
  "name": "FGRibreau",
  "github": "https://github.com/fgribreau/",
  "likes": [
    "code",
    "cheese",
    "meat"
  ],
  "contact": {
    "email": "[email protected]",
    "twitter": "@FGRibreau"
  }
}

This means you use can use gron with grep and other tools to modify JSON:

▶ cat testdata/two.json | gron | grep likes | ungron
{
  "likes": [
    "code",
    "cheese",
    "meat"
  ]
}

To preserve array keys, arrays are padded with null when values are missing:

▶ cat testdata/two.json | gron | grep likes | grep -v cheese
json.likes = [];
json.likes[0] = "code";
json.likes[2] = "meat";
▶ cat testdata/two.json | gron | grep likes | grep -v cheese | ungron
{
  "likes": [
    "code",
    null,
    "meat"
  ]
}

Changelog

Todo

This whole project (up to v2.0.1, from idea to this README) was done in 1 hour, so there is some missing features in this implementation (if you can call 3 line of codes an implementation).

  • [ ] stream support (large file support)

Credits

This module is entirely inspired by tomnomnom/gron but instead of reinventing the wheel it relies on nodejs+flat.

You want to support my work?

I maintain this project in my free time, if it helped you, well, I would be grateful to buy a beer thanks to your paypal or Bitcoins, donation!

Francois-Guillaume Ribreau ([email protected])