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

gson-query-cli

v1.2.0

Published

json-pointer cli utilities for querying and transforming data

Downloads

18

Readme

Query and transform your json data using an extended glob-pattern. This is a really helpful tool to quickly

  • fuzzy search json-data matching some search properties
  • transform data with consistent structures
  • extract information from json-data

This is the cli to gson-query

npm install gson-query-cli -g

Usage

cat some.json | gq query

Example cat package.json | gq '/keywords/*' will print all keywords

cli
query
json
json-pointer
glob-pattern
library

or read a file directly gq -f package.json '/keywords/*'

Query

The query syntax is explained in detail at gson-query#query

Options

For further details and options type $ gq -h.

Usage: gq [options] query

DESCRIPTION
The gq utility will apply the query on the given json data and write
any results to the standard output. Per default, each result is written per
line.

query
A basic query describes a path from the root of a json object to the
target destination, e.g. '/first/property'. To find multiple matches replace
any property with a wildcard '*', e.g. '/first/*' wich will return any
property from 'first'. To search independent of the depth of a target, use
the glob-pattern '**', e.g. '/**/second' will return any property 'second'
regardless of the depth within the json file.

To further narrow down the search result, use a regular expression like
'/**/{alf.*}' and/or add additional queries to the targets property
structure with '/**?alf:!undefined&&alf:!true'. For further details goto
https://github.com/sagold/gson-query

value formats
Value formats can be modified with options
-j  value as valid json value in one line (default for objects and arrays)
-b  value as valid json format, multiple lines

output options
Different output options may be specified. A per line output is set by default,
but can be changed in the following order (highest option matches first)
-a  prints all matches in one valid json array like [ %value ]
-o  prints all matches in one valid json object like { %pointer: %value }
-p  specifies a pattern for per line output
-t  prints json-pointer of matches per line

pattern
For customized output a pattern may be given, which is a string containing
variables (%name) which will be replaced by the specified contents.

Example pattern: $ gq -p '%number/%total %pointer: %value'

Valid variable names are:
%value     - the matching value
%key       - the property name of the match
%parent    - the value of the parent (which contains the match)
%pointer   - the json-pointer to the target
%index     - the index of the match
%position  - the position of the match (index starting at 1)
%total     - the total number of matches

Examples
$ gq -f demo.json '/nodes/*/services/*?state:!healthy'
$ cat demo.json | gq '/nodes/*/services/*?state:!healthy'

Options:

-a, --array                print all matches as a valid json like [%match]. Overrides -o, -t, -p.
-b, --beautify             pretty print the result in json format (multiple lines)
-d, --debug                show stack trace of errors
-f, --filename <filename>  reads the json data from the given file
-j, --json                 print the result in json format (one-liner). Will always json-print objects and arrays
-o, --object               print all matches as a valid json map {%pointer: %match}. Overrides -t -p.
-p, --pattern <pattern>    print the result in the given pattern. @see pattern description
-t, --target               returns the json-pointer of each match (instead of its value)
-h, --help                 output usage information