jsonrange
jsonrange OPTIONS [DOT_PATH_EXPRESSION]
jsonrange returns returns a range of values based on the JSON structure being read and options applied. Without options the JSON structure is read from standard input and writes a list of keys to standard out. Keys are either attribute names or for arrays the index position (counting form zero). If a DOT_PATH_EXPRESSION is included on the command line then that is used to generate the results. Using options to can choose to read the JSON data structure from a file, write the output to a file as well as display values instead of keys. a list of “keys” of an index or map in JSON.
Using options it can also return a list of values. The JSON object is read from standard in and the resulting list is normally written to standard out. There are options to read or write to files. Additional parameters are assumed to be a dot path notation select the parts of the JSON data structure you want from the range.
DOT_PATH_EXPRESSION is a dot path stale expression indicating what you want range over. E.g.
The path can be chained together
Working with a map
echo '{"name": "Doe, Jane", "email":"jane.doe@example.org", "age": 42}' \
| jsonrange
This would yield
name
email
age
Using the -values option on a map
echo '{"name": "Doe, Jane", "email":"jane.doe@example.org", "age": 42}' \
| jsonrange -values
This would yield
"Doe, Jane"
"jane.doe@example.org"
42
Working with an array
echo '["one", 2, {"label":"three","value":3}]' | jsonrange
would yield
0
1
2
Using the -values option on the same array
echo '["one", 2, {"label":"three","value":3}]' | jsonrange -values
would yield
one
2
{"label":"three","value":3}
Checking the length of a map or array or number of keys in map
echo '["one","two","three"]' | jsonrange -length
would yield
3
Check for the index of last element
echo '["one","two","three"]' | jsonrange -last
would yield
2
Check for the index value of last element
echo '["one","two","three"]' | jsonrange -values -last
would yield
"three"
Limitting the number of items returned
echo '[10,20,30,40,50]' | %!s(MISSING) -limit 2
would yield
1
2
Limitting the number of values returned
echo '[10,20,30,40,50]' | %!s(MISSING) -values -limit 2
would yield
10
20
jsonrange 1.2.10