Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

fp-json-cli

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

fp-json-cli

Simple cli inspired by jq

  • 0.1.2
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

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

NameAlias
add
constantc
countlen
dividediv
entries
equalseq
everyand
filter
flatMapchain
flow
getpluck
greaterThangt
greaterThanEqualsgte
identityid, i
includeshas
lessThanlt
lessThanEqualslte
map
multiplymul
not
notEqualsneq
omit
pick
projectp
range
reverse
skip
someor
sort
subractsub
take
unionu
uniqueuniq

TODO

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

Keywords

FAQs

Package last updated on 26 Feb 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc