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

fp-json-cli

v0.1.2

Published

Simple cli inspired by jq

Downloads

95

Readme

FP Json CLI

version tests NPM Version

fq is a command line tool that embodies the Unix philosophy of small, composable functions that can be piped together using the | operator. It simplifies the process of filtering and querying JSON data, drawing inspiration from popular tools like jq et al., while aiming to provide a more familiar experience for JavaScript and Typescript developers.

Table of Contents

Installation

npm install --global fp-json-cli
yarn global add fp-json-cli
pnpm install --global fp-json-cli

Usage

You can either read JSON data from stdin by using a command like cat package.json | fq ".name", or provide the file name as the second argument, eg. fq ".name" package.json.

One of the more interesting use cases for fq is when you want to change the format of JSON data. By piping together multiple fq operators, you can transform JSON data from one format to another easily.

Examples

List all Operators in Reverse Order

fq list --json | fq "chain(.alias) | sort(.) | reverse(.)"
  • fq list --json: Write all available operators in JSON format to stdout.
  • chain(.alias): Is a shorthand for flatMap(get(alias)), which concatenates the alias JSON arrays together.
  • sort(.): Sort the JSON array.
  • reverse(.): Reverse the sorted array.

Remove Properties from API Data

curl -X GET https://jsonplaceholder.typicode.com/users > users.json # save response to a file
fq -o users-out.json "map(u(omit(company), p(address, .address|omit(geo)))) | filter(.id >= 4) | take(2)" users.json
  • map(u(omit(company), p(address, .address|omit(geo)))): This operation maps each user object in the JSON data. It omits the company field from the user object and re-projects the address field without the geo field.
  • filter(.id >= 4): Filters the mapped user objects based on the condition that the id field is greater than or equal to 4.
  • take(2): Takes the first 2 filtered user objects.

The final result of these operations is written to the users-out.json file.

CLI

fq/0.1.0

Usage:
  $ fq <query> [file]

Commands:
  <query> [file]  Run fp style operators on input file or stdin
  list            List available operators

For more info, run any command with the `--help` flag:
  $ fq --help
  $ fq list --help

Options:
  -o, --out <path>  Write the result to a file 
  --no-nl           Control new line at the end output (default: true)
  --show-ast        Dump AST to stdout 
  --show-ir         Dump intermediate representation to stdout 
  -h, --help        Display this message 
  -v, --version     Display version number 

Examples:
fq "map(union(pick(email, name), project(age, meta.age)) | filter(.age > 2)" users.json

Operators

| Name | Alias | | :---------------- | :---- | | add | | | constant | c | | count | len | | divide | div | | entries | | | equals | eq | | every | and | | filter | | | flatMap | chain | | flow | | | get | pluck | | greaterThan | gt | | greaterThanEquals | gte | | identity | id, i | | includes | has | | lessThan | lt | | lessThanEquals | lte | | map | | | multiply | mul | | not | | | notEquals | neq | | omit | | | pick | | | project | p | | range | | | reverse | | | skip | | | some | or | | sort | | | subract | sub | | take | | | union | u | | unique | uniq |

TODO

  • [ ] Error reporting
  • [ ] Type checking
  • [ ] Reduce/fold operator
  • [ ] Streaming parsing and serializing for large files
  • [ ] Highlight output similar to jq