30
30
< section >
31
31
< h1 > USAGE</ h1 >
32
32
33
- < pre > < code > jsonrange [OPTIONS] JSON_EXPRESSION
33
+ < pre > < code > jsonrange [OPTIONS] [DOT_PATH_EXPRESSION]
34
34
</ code > </ pre >
35
35
36
36
< h2 > SYSNOPSIS</ h2 >
37
37
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 >
42
62
43
63
< 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 >
45
65
</ ul >
46
66
47
67
< h2 > OPTIONS</ h2 >
48
68
49
69
< pre > < code > -d set delimiter for range output
50
70
-delimiter set delimiter for range output
51
- -dotpath range on given dot path
52
71
-h display help
53
72
-i read JSON from file
54
73
-input read JSON from file
55
74
-l display license
75
+ -last return the index of the last element in list (e.g. length - 1)
56
76
-length return the number of keys or values
57
- -last return the index of the last element
58
77
-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
60
80
-v display version
81
+ -values return the values instead of the keys
61
82
</ code > </ pre >
62
83
63
84
< h2 > EXAMPLES</ h2 >
64
85
65
86
< p > Working with a map</ p >
66
87
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
68
90
</ code > </ pre >
69
91
70
92
< p > This would yield</ p >
@@ -74,9 +96,34 @@ <h2>EXAMPLES</h2>
74
96
age
75
97
</ code > </ pre >
76
98
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
+
77
112
< p > Working with an array</ p >
78
113
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
80
127
</ code > </ pre >
81
128
82
129
< p > would yield</ p >
@@ -86,19 +133,19 @@ <h2>EXAMPLES</h2>
86
133
{"label":"three","value":3}
87
134
</ code > </ pre >
88
135
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 >
90
137
91
- < pre > < code > jsonrange -length '["one","two","three"]'
138
+ < pre > < code class =" language-shell " > echo '["one","two","three"]' | jsonrange -length
92
139
</ code > </ pre >
93
140
94
141
< p > would yield</ p >
95
142
96
143
< pre > < code > 3
97
144
</ code > </ pre >
98
145
99
- < p > Checking the last element index of a an array </ p >
146
+ < p > Check for the index value of last element </ p >
100
147
101
- < pre > < code > jsonrange -last '["one","two","three"]'
148
+ < pre > < code class =" language-shell " > echo '["one","two","three"]' | jsonrange -last
102
149
</ code > </ pre >
103
150
104
151
< p > would yield</ p >
@@ -108,7 +155,7 @@ <h2>EXAMPLES</h2>
108
155
109
156
< p > Limitting the number of items returned</ p >
110
157
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
112
159
</ code > </ pre >
113
160
114
161
< p > would yield</ p >
0 commit comments