3030< section >
3131< h1 > USAGE</ h1 >
3232
33- < pre > < code > jsonrange [OPTIONS] JSON_EXPRESSION
33+ < pre > < code > jsonrange [OPTIONS] [DOT_PATH_EXPRESSION]
3434</ code > </ pre >
3535
3636< h2 > SYSNOPSIS</ h2 >
3737
38- < p > jsonrange turns either the JSON expression that is a map or array into delimited
39- elements suitable for processing in a “for” style loop in Bash. If the
40- JSON expression is an array then the elements of the array are returned else
41- if the expression is a map/object then the keys or attribute names are turned.</ p >
38+ < p > jsonrange returns returns a range of values based on the JSON structure being read and
39+ options applied. Without options the JSON structure is read from standard input
40+ and writes a list of keys to standard out. Keys are either attribute names or for
41+ arrays the index position (counting form zero). If a DOT_PATH_EXPRESSION is included
42+ on the command line then that is used to generate the results. Using options to
43+ can choose to read the JSON data structure from a file, write the output to a file
44+ as well as display values instead of keys. a list of “keys” of an index or map in JSON.</ p >
45+
46+ < p > Using options it can also return a list of values. The JSON object is read from standard in and the
47+ resulting list is normally written to standard out. There are options to read or
48+ write to files. Additional parameters are assumed to be a dot path notation
49+ select the parts of the JSON data structure you want from the range.</ p >
50+
51+ < p > DOT_PATH_EXPRESSION is a dot path stale expression indicating what you want range over.
52+ E.g.</ p >
53+
54+ < ul >
55+ < li > < em > .</ em > would indicate the whole JSON data structure read is used to range over</ li >
56+ < li > < em > .name</ em > would indicate to range over the value pointed at by the “name” attribute</ li >
57+ < li > < em > [“name”]</ em > would indicate to range over the value pointed at by the “name” attribute</ li >
58+ < li > < em > [0]</ em > would indicate to range over the value held in the zero-th element of the array</ li >
59+ </ ul >
60+
61+ < p > The path can be chained together</ p >
4262
4363< ul >
44- < li > EXPRESSION can be an empty string contains a JSON array or map .</ li >
64+ < li > < em > .name.family </ em > would point to the value heald by the “name” attributes’ “family” attribute .</ li >
4565</ ul >
4666
4767< h2 > OPTIONS</ h2 >
4868
4969< pre > < code > -d set delimiter for range output
5070 -delimiter set delimiter for range output
51- -dotpath range on given dot path
5271 -h display help
5372 -i read JSON from file
5473 -input read JSON from file
5574 -l display license
75+ -last return the index of the last element in list (e.g. length - 1)
5676 -length return the number of keys or values
57- -last return the index of the last element
5877 -limit limit the number of items output
59- -p range on given dot path
78+ -o write to output file
79+ -output write to output file
6080 -v display version
81+ -values return the values instead of the keys
6182</ code > </ pre >
6283
6384< h2 > EXAMPLES</ h2 >
6485
6586< p > Working with a map</ p >
6687
67- < pre > < code > jsonrange '{"name": "Doe, Jane", "email":"
[email protected] ", "age": 42}'
88+ < pre > < code class ="
language-shell "
> echo '{"name": "Doe, Jane", "email":"
[email protected] ", "age": 42}' \
89+ | jsonrange
6890</ code > </ pre >
6991
7092< p > This would yield</ p >
@@ -74,9 +96,34 @@ <h2>EXAMPLES</h2>
7496 age
7597</ code > </ pre >
7698
99+ < p > Using the -values option on a map</ p >
100+
101+ < pre > < code class ="
language-shell "
> echo '{"name": "Doe, Jane", "email":"
[email protected] ", "age": 42}' \
102+ | jsonrange -values
103+ </ code > </ pre >
104+
105+ < p > This would yield</ p >
106+
107+ < pre > < code > "Doe, Jane"
108+ 109+ 42
110+ </ code > </ pre >
111+
77112< p > Working with an array</ p >
78113
79- < pre > < code > jsonrange '["one", 2, {"label":"three","value":3}]'
114+ < pre > < code class ="language-shell "> echo '["one", 2, {"label":"three","value":3}]' | jsonrange
115+ </ code > </ pre >
116+
117+ < p > would yield</ p >
118+
119+ < pre > < code > 0
120+ 1
121+ 2
122+ </ code > </ pre >
123+
124+ < p > Using the -values option on the same array</ p >
125+
126+ < pre > < code class ="language-shell "> echo '["one", 2, {"label":"three","value":3}]' | jsonrange -values
80127</ code > </ pre >
81128
82129< p > would yield</ p >
@@ -86,19 +133,19 @@ <h2>EXAMPLES</h2>
86133 {"label":"three","value":3}
87134</ code > </ pre >
88135
89- < p > Checking the length of a map or array</ p >
136+ < p > Checking the length of a map or array or number of keys in map </ p >
90137
91- < pre > < code > jsonrange -length '["one","two","three"]'
138+ < pre > < code class =" language-shell " > echo '["one","two","three"]' | jsonrange -length
92139</ code > </ pre >
93140
94141< p > would yield</ p >
95142
96143< pre > < code > 3
97144</ code > </ pre >
98145
99- < p > Checking the last element index of a an array </ p >
146+ < p > Check for the index value of last element </ p >
100147
101- < pre > < code > jsonrange -last '["one","two","three"]'
148+ < pre > < code class =" language-shell " > echo '["one","two","three"]' | jsonrange -last
102149</ code > </ pre >
103150
104151< p > would yield</ p >
@@ -108,7 +155,7 @@ <h2>EXAMPLES</h2>
108155
109156< p > Limitting the number of items returned</ p >
110157
111- < pre > < code > jsonrange -limit 2 '[1,2,3,4,5]'
158+ < pre > < code class =" language-shell " > echo '[1,2,3,4,5]' | jsonrange -limit 2
112159</ code > </ pre >
113160
114161< p > would yield</ p >
0 commit comments