JSON manipulation tools for command line inspired by Ramda.js, a practical functional JavaScript library inspired by Clojure.
$ echo '{"status":"RUNNING"}' | R path status
RUNNING
$ echo '{"age":60,"color":"blue", "score": 3}' | R pick age score
{"age": 60, "score": 3}
$ echo '[1, 2, 3, 4]' | R head
1
$ echo '[1, 2, 3, 4]' | R tail
[2, 3, 4]
$ echo '{"age":60}' | R eq '{"age":60}'
true
$ echo '{"age":60}' | R not eq '{"name":"joe"}'
true
Version: 0.2
Download binary for your platform:
RCLI is written in Go and requires go
command to build.
git clone https://github.com/jpospychala/rcli.git
cd rcli
make
sudo make install
Usage: R <func> [arguments...]
Functions can be stacked, so that result of one function is passed as input to next function, for example:
$ echo '[1]' | R append 2 each
1
2
Input can contain single JSON object or sequence of objects, in which case each object is processed by function chain, for example:
$ echo -e '{"name":"Jack","sex":"male"}{"name":"Wendy","sex":"female"}' | R path name
Jack
Wendy
append appends object to list
Example:
$ echo '[1]' | R append 2
[1,2]
concat [list] concatenates two lists
Example:
$ echo '[1,2]' | R concat '[3,4]'
[1,2,3,4]
contains true if input contains object
Example:
$ echo '[1, 2]' | R contains 1
true
each prints each list element in new line
Example:
$ echo '[1,2,3]' | R each
1
2
3
eq compares stdin with first argument for equality
Example:
$ echo '{"a":{"b":1}}' | R eq '{"a":{"b":1}}'
filter returns list of objects matching predicate
Example:
$ echo '[{"a":1, "b":2}]' | R filter where '{"a":1}'
[{"a":1,"b":2}]
find first object from list matching predicate
Example:
$ echo '[{"a":1, "b":2}]' | R find where '{"a":1}'
{"a":1,"b":2}
$ echo '[{"a":1, "b":2}]' | R find where '{"a":2}'
$
head first element of a list
Example:
$ echo '[1,2,3,4]' | R head
1
help prints usage details
keys returns object property names
Example:
$ echo '{"a":1,"b":2}' | R keys
["a","b"]
length [list] number of elements in list
Example:
$ echo '[1,2,3,4]' | R length
4
map maps list elements using func
Example:
$ echo '[{"a":1},{"a":2}]' | R map path a
[1,2]
mixin adds obj properties into input object
Example:
$ echo '{"a":1, "b":2}' | R mixin '{"b": 5,"c":3}'
{"a":1,"b":5,"c":3}
not inverts boolean result of following function
Example:
$ echo '0' | R not eq '1'
omit [list] returns object without specified properties
Example:
$ echo '{"a":1,"b":2}' | R omit a
{"b":2}
path returns object at period-delimited path
Example:
$ echo '{"a":{"b":true}}' | R path a.b
true
pick [list] returns object with only specified properties
Example:
$ echo '{"a":1,"b":2}' | R pick a
{"a":1}
tail all but first elements of a list
Example:
$ echo '[1,2,3,4]' | R tail
[2,3,4]
values returns list of object values
Example:
$ echo '{"a":1,"b":2}' | R values
[1,2]
version prints R version
where checks if object matches spec obj
Example:
$ echo '{"a":1, "b":2}' | R where '{"a": 1}'
{"a":1, "b":2}
$ echo '{"a":1, "b":2}' | R where '{"a": b}'
$