• Stars
    star
    294
  • Rank 141,303 (Top 3 %)
  • Language
    JavaScript
  • License
    MIT License
  • Created about 8 years ago
  • Updated over 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

gron - Make JSON greppable!

gron - Make JSON greppable!.


Deps NPM version

Get help on Codementor available-for-advisory extra Slack

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 🚀! 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

❤️ Shameless plug

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])

More Repositories

1

mailchecker

📫 Cross-language temporary (disposable/throwaway) email detection library. Covers 55 734+ fake email providers.
PHP
1,486
star
2

check-build

🎯 Check-build - Verifies that your NodeJS project follows team conventions, is well written, up to date and secure.
JavaScript
686
star
3

match-when

🐚 Pattern matching for modern JavaScript
JavaScript
528
star
4

spinners

🛎 60+ Elegant terminal spinners for Rust
Rust
462
star
5

jq.node

jq.node - like jq but WAY MORE powerful (300+ helpers 🔥 & 1.45M modules 😱)
JavaScript
418
star
6

dot-clipboard

👝 dot-clipboard monitors your clipboard and runs scripts based on its content
JavaScript
416
star
7

node-language-detect

🇫🇷 NodeJS language detection library using n-gram
JavaScript
375
star
8

node-request-retry

💂‍♂️ Wrap NodeJS request module to retry http requests in case of errors
JavaScript
346
star
9

forever-webui

[unmaintained] 📡 A simple web UI for efficient NodeJS processes administration
JavaScript
293
star
10

ui-predicate

Finally a Predicate/Rule Editor UI component for the Web 🚀
JavaScript
160
star
11

node-unidecode

📃 ASCII transliterations of Unicode text
JavaScript
130
star
12

import-tweets-to-mastodon

How to import tweets to mastodon (e.g. https://framapiaf.org )
JavaScript
87
star
13

spm

spm • Scala Package Manager - it's based on sbt but npm-like :trollface:
Shell
79
star
14

influxdb-cli

SQL CLI for InfluxDB
JavaScript
70
star
15

common-env

🔑 The only configuration library you will ever need
JavaScript
70
star
16

sql-convention

👌 The only SQL conventions you will ever need
57
star
17

google-spreadsheet-cli

📊 CLI for reading and writing data into Google Spreadsheet
JavaScript
52
star
18

node-truncate

🐙 Truncate text and keeps urls safe.
JavaScript
52
star
19

network-config

Network configuration for NodeJS
JavaScript
50
star
20

spotify-downloader

A proof-of-concept that transforms a Spotify playlist to a direct-download list
JavaScript
50
star
21

stripe-schema

Complete Stripe (🥰) schema (as of 2019-10-09): for learning and inspiration.
Shell
34
star
22

xobject-observe

🔬 A cross-browser object property observer using ES6 proxy with a fallback on dirty-checking.
JavaScript
33
star
23

if-exp

🎩 Conditional expressions for JavaScript
JavaScript
32
star
24

postgresql-to-amqp

PostgreSQL to AMQP, forward PostgreSQL notifications to an AMQP queue.
Rust
30
star
25

node-amqp-tool

AMQP-tool - Import & export data from/to an AMQP/RabbitMQ broker
JavaScript
26
star
26

kubectx-rs

Switch between Kubernetes contexts 🏎
Shell
25
star
27

pound

Pound - High-level asset Manager for Node.js/Express
JavaScript
25
star
28

alfred-crates

Workflow for searching Rust crates from Alfred
Rust
21
star
29

jsobjectdiff

Ensure that two JavaScript files containing objects have the same keys and display differences
JavaScript
21
star
30

node-children

Concurrent tasks computation among NodeJS child processes (vertical scaling)
JavaScript
20
star
31

npm-interactive-scripts

⚡️Fast Interactive CLI for npm scripts
JavaScript
18
star
32

stripe-update-card

💳 Expose a page that let your customers update their payment information on Stripe.
Rust
18
star
33

redis-tool

Redis-tool - Little helpers for Redis
JavaScript
17
star
34

json-schema-documentation

JSON-Schema documentor (generator, cli, themes)
JavaScript
16
star
35

Growl-Chrome-Notification

Notifications Growl pour Google Chrome :: Proof of concept :: HTML5 Web Notification API + WebSocket + NodeJS
JavaScript
16
star
36

mixpanel_export_people

Export Mixpanel people properties to an Excel Compatible CSV
JavaScript
16
star
37

node-tolerant-url-parser

Overly tolerant url parser specialized in parsing protocol, auth (even invalid ones), host and port url parts.
JavaScript
15
star
38

droplr-backup

How to backup your droplr account
JavaScript
15
star
39

stream-valve

🔐 Ensure that a stream disconnects if it goes over `maxBytes` `perSeconds`
JavaScript
14
star
40

filesync

👥 Unidirectional 1-N file syncing with history and local merging
JavaScript
14
star
41

redistree

RedisTree - load & save Trees to Redis using sets
JavaScript
13
star
42

request-api

NodeJS request library as HTTP API
JavaScript
13
star
43

node-redis-info

Redis info string parser for NodeJS
JavaScript
13
star
44

this-is-your-life

This if your life
JavaScript
12
star
45

rss-to-amp-stories

RSS to AMP Stories ⚡️
HTML
12
star
46

latenize

NPM/NodeJS port of Semplice latenize
JavaScript
12
star
47

amqp-replay

📹 Replay messages from (RabbitMQ) AMQP dead-letter queue
JavaScript
12
star
48

smtp-to-sendgrid-gateway

Forward emails from SMTP requests to the Sendgrid API. Useful when the cloud provider does not allow outbound connections on ports 25, 465, 587.
JavaScript
11
star
49

my-first-nodejs-service

🐾 Workshop my first nodejs service
JavaScript
11
star
50

node-transacemail

Transactional Email & Templated Email for NodeJS done right
JavaScript
11
star
51

stargazerz

Stargazerz - export repository 🌟 stargazers 🌟 profile as JSON
JavaScript
9
star
52

kubectx

Fastest switch between #Kubernetes contexts 🏎
JavaScript
9
star
53

mixpanel-cli

🎩 mixpanel-cli - A complete CLI to query Mixpanel API
JavaScript
9
star
54

stripe-integration

Easiest Stripe Integration (ever)
Rust
9
star
55

rss-to-lametric

Your favorite RSS feed directly from your LaMetric 🎩
Rust
8
star
56

tumblr-analysis

Extract every tumblr posts as JSON from a blog and analyze them.
JavaScript
8
star
57

node-amqp-dsl

AMQP-DSL is a fluent interface for AMQP (RabbitMQ,...) on NodeJS
CoffeeScript
8
star
58

123PeopleRemover-proxy

Proxy pour 123PeoplerRemover à installer sur votre serveur
PHP
8
star
59

jQuery-plugin-attributeObserver

jQuery plugin for observing html element's property changes
JavaScript
8
star
60

node-nice-console

Patch NodeJS console methods in order to add timestamp information
JavaScript
8
star
61

gcloud

Google Cloud API client for Rust
Rust
8
star
62

jQuery-plugin-fireEvent

jQuery FireEvent - Plugin for firing real DOM events
JavaScript
8
star
63

jQuery-plugin-getPath

jQuert getPath - Find a (possible) jQuery selector of an HTML element.
JavaScript
7
star
64

node-ast-inlining

Node Ast Inlining is a small (~200 LOC) library that inline and expand function call
JavaScript
7
star
65

preg_replace---preg_replace_callback-in-javascript

PHP functions preg_replace & preg_replace_callback javascript equivalent
JavaScript
7
star
66

node-x509-certificate

Retrieve the public TLS certificate in x509 format from a distant host
JavaScript
7
star
67

lool

:trollface: Infinitely recursive self-installing useless package.
6
star
68

querystring

🦄 Querystring for Rust
Rust
5
star
69

twitterremover

How I "hijacked" Topsy private search api to remove my first 5000+ tweets
JavaScript
5
star
70

scaleway-api-client

☁ Scaleway NodeJS API Client 🚀
JavaScript
5
star
71

self-worth

See jeffreybaird/self-worth
Ruby
5
star
72

jscs2doc

🎊 Convert .jscsrc (javascript code-style configuration) to a human readable format
JavaScript
5
star
73

rk

Original idea by @stockholmux in Dancing around strings in Node.js and Redis
JavaScript
5
star
74

json-combine

Generate every possible combination of values
JavaScript
4
star
75

chrome-freeze-tab-title

Freeze Tab Title & Favicon Chrome Extension - Increase productivity & Reduce procrastination 🌟🌟
JavaScript
4
star
76

backbone-cappedcollection

Capped Collections for BackboneJS
JavaScript
4
star
77

Trickle-clone

A Quick & Dirty trickle clone
JavaScript
4
star
78

valid-json-template

Use a (valid) JSON as a template that produce another valid JSON as a result
JavaScript
4
star
79

terraform-workspace-switcher

Fastest switch between Terraform workspaces
Shell
4
star
80

clipboard-watcher

Listen to clipboard change (OSX only)
JavaScript
4
star
81

bmw_oss_dvd

♣️ BMW Open Source Software (OSS) DVD - I received for my BMW X3
3
star
82

big-brother

Web2Day Hackathon 2011
JavaScript
3
star
83

JSCSSP

JSCSSP without DOM pollution
JavaScript
3
star
84

app-demonstrator

Proof of Concept - (iPhone & co) Application demonstrator
JavaScript
3
star
85

postgrest-patch-request-trigger

How PostgreSQL triggers works when called with a PostgREST PATCH HTTP request
PLpgSQL
3
star
86

hostname-is-private

:squirrel: Check whether or not an hostname refers to a private IP
JavaScript
3
star
87

join-events

▶️ Join events stream compatible with event emitter
JavaScript
3
star
88

url-is-private

Check whether or not an url refer to a private IP
JavaScript
3
star
89

maintainers-convention

💂‍♂️ Ensure a MAINTAINERS file exist inside every repository of a Github Organisation
JavaScript
3
star
90

node-asynccallguard

Make all calls to a function queued and asynchronously guarded
JavaScript
3
star
91

ai-rom

TP cours d'IA
C
2
star
92

cancelable

Cancelable JavaScript functions
JavaScript
2
star
93

request-when

Request + WhenJS
JavaScript
2
star
94

ai-GeneticAlgorithm

Genetical Algorithm w/ Chessboard
C
2
star
95

elasticsearch-exceptions

Parse Elasticsearch exception responses and transform them into JavaScript Errors
JavaScript
2
star
96

Kuripotxt

A simple PHP Class for sending sms using Kuripotxt
2
star
97

stretchtext

StretchText
JavaScript
2
star
98

iPhone-Particles

Simple iPhone Particles App
JavaScript
2
star
99

docker-jenkins-slave

💪 Run a Jenkins slave in docker AND access to docker cli from jobs
2
star
100

node-transacemail-mandrill

Mandrill mailProvider for node-transacemail
JavaScript
2
star