Skip to content

A command line tool to process (sort, filter, pluck, etc.) JSON text

License

Notifications You must be signed in to change notification settings

craigerm/jeep-cli

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

13 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

JEEP

JEEP is a small command line utility for processing JSON text. It provides, filtering, sorting, plucking fields, etc. It was created to be used when making API calls with curl that return JSON.

Quick examples:

Update: Pull requests default to Open by default so this example is not the best, but you ge the idea. I'll update this soon hopefully, maybe, probably not.

# Get all tag names for rails repository
curl https://api.github.com/repos/rails/rails/tags | jeep -p "name"

# Get count of tag names for rails repository
curl https://api.github.com/repos/rails/rails/tags | jeep -c

# Get all open pull requests
curl https://api.github.com/repos/rails/rails/pulls | jeep -w '{state: "Open"}'

# Get count of all open pull requests
curl https://api.github.com/repos/rails/rails/pulls | jeep -w '{state: "Open"}' -c

Installation

npm install -g jeep-cli

Documentation

Most arguments can be combined. For example you can filter, sort and return the first item remaining. Or filter the data and get the count of the remaining items.

Count items in array (-c or --count)

echo '["John","Steve"]' | jeep -c # returns 2

Return first item in array (-f or --first)

echo '["John,"Steve"]' | jeep -f # returns "John"

Returns keys for an object (k or --keys)

# Returns ["id","name","email"]
echo '{"id": 1, "name": "John", email: "[email protected]"}' | jeep -k

Return last item in array (-l or --last)

echo '["John,"Steve"]' | jeep -l # returns "Steve"

Pluck property names from array (-p or --pluck)

Pluck can be be a single property or a comma separated list of properties

# returns ["john","steve"]
echo '[{"name":"john","id":1},{"name":"steve","id":2}]' | jeep -p "name" 

# returns title and status of all pull requests
curl https://api.github.com/repos/rails/rails/pulls | jeep -p "title,status"

Sort by property name (-s --sortBy)

# Returns array sorted by id in ascending order
echo '[{id:5},{id:7},{id:3}]' | jeep -s "id"

Sort by property name descending (-S --sortByDesc)

# Returns array sorted by id in descending order
echo '[{id:5},{id:7},{id:3}]' | jeep -S "id"

Simple filter by property values (-w --where)

# Filters records by 'Open' state
curl https://api.github.com/repos/rails/rails/pulls | jeep -w '{state:"Open"}'

Other

jeep -h # View help (-h or --help)
jeep -v # View version (-V or --version)

Formatted and colourful JSON output

Right now I just use the awesome pjson tool for this.

curl https://api.github.com/repos/rails/rails/pulls | jeep  -s "title" | pjson

The name JEEP?

Json Eliminater, Editor and Processor...ok that's not really true. I just wanted a three or four letter name that started with J. And all the good ones are taken of course...

License

Copyright (c) Craig MacGregor 2015 under MIT LICENSE

About

A command line tool to process (sort, filter, pluck, etc.) JSON text

Resources

License

Stars

Watchers

Forks

Packages

No packages published