-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathjsonrange.1.html
175 lines (173 loc) · 5.92 KB
/
jsonrange.1.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
<!DOCTYPE html>
<html>
<head>
<title>Caltech Library's Digital Library Development Sandbox</title>
<link href='https://fonts.googleapis.com/css?family=Open+Sans' rel='stylesheet' type='text/css'>
<link rel="stylesheet" href="/css/site.css">
</head>
<body>
<header>
<a href="http://library.caltech.edu"><img src="/assets/liblogo.gif" alt="Caltech Library logo"></a>
</header>
<nav>
<ul>
<li><a href="/">Home</a></li>
<li><a href="./">README</a></li>
<li><a href="LICENSE">LICENSE</a></li>
<li><a href="INSTALL.html">INSTALL</a></li>
<li><a href="user-manual.html">User Manual</a></li>
<li><a href="how-to/">Tutorials</a></li>
<li><a href="search.html">Search Docs</a></li>
<li><a href="about.html">About</a></li>
<li><a href="https://github.com/caltechlibrary/datatools">GitHub</a></li>
</ul>
</nav>
<section>
<h1 id="name">NAME</h1>
<p>jsonrange</p>
<h1 id="synopsis">SYNOPSIS</h1>
<p>jsonrange <a href="#options">OPTIONS</a> [DOT_PATH_EXPRESSION]</p>
<h1 id="description">DESCRIPTION</h1>
<p>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.</p>
<p>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.</p>
<p>DOT_PATH_EXPRESSION is a dot path stale expression indicating what
you want range over. E.g.</p>
<ul>
<li>. would indicate the whole JSON data structure read is used to range
over</li>
<li>.name would indicate to range over the value pointed at by the
“name” attribute</li>
<li>[“name”] would indicate to range over the value pointed at by the
“name” attribute</li>
<li>[0] would indicate to range over the value held in the zero-th
element of the array</li>
</ul>
<p>The path can be chained together</p>
<ul>
<li>.name.family would point to the value heald by the “name”
attributes’ “family” attribute.</li>
</ul>
<h1 id="options">OPTIONS</h1>
<dl>
<dt>-help</dt>
<dd>
display help
</dd>
<dt>-license</dt>
<dd>
display license
</dd>
<dt>-version</dt>
<dd>
display version
</dd>
<dt>-d, -delimiter</dt>
<dd>
set delimiter for range output
</dd>
<dt>-i, -input</dt>
<dd>
read JSON from file
</dd>
<dt>-last</dt>
<dd>
return the index of the last element in list (e.g. length - 1)
</dd>
<dt>-length</dt>
<dd>
return the number of keys or values
</dd>
<dt>-limit</dt>
<dd>
limit the number of items output
</dd>
<dt>-nl, -newline</dt>
<dd>
if true add a trailing newline
</dd>
<dt>-o, -output</dt>
<dd>
write to output file
</dd>
<dt>-quiet</dt>
<dd>
suppress error messages
</dd>
<dt>-values</dt>
<dd>
return the values instead of the keys
</dd>
</dl>
<h1 id="examples">EXAMPLES</h1>
<p>Working with a map</p>
<pre><code> echo '{"name": "Doe, Jane", "email":"[email protected]", "age": 42}' \
| jsonrange</code></pre>
<p>This would yield</p>
<pre><code> name
email
age</code></pre>
<p>Using the -values option on a map</p>
<pre><code> echo '{"name": "Doe, Jane", "email":"[email protected]", "age": 42}' \
| jsonrange -values</code></pre>
<p>This would yield</p>
<pre><code> "Doe, Jane"
"[email protected]"
42</code></pre>
<p>Working with an array</p>
<pre><code> echo '["one", 2, {"label":"three","value":3}]' | jsonrange</code></pre>
<p>would yield</p>
<pre><code> 0
1
2</code></pre>
<p>Using the -values option on the same array</p>
<pre><code> echo '["one", 2, {"label":"three","value":3}]' | jsonrange -values</code></pre>
<p>would yield</p>
<pre><code> one
2
{"label":"three","value":3}</code></pre>
<p>Checking the length of a map or array or number of keys in map</p>
<pre><code> echo '["one","two","three"]' | jsonrange -length</code></pre>
<p>would yield</p>
<pre><code> 3</code></pre>
<p>Check for the index of last element</p>
<pre><code> echo '["one","two","three"]' | jsonrange -last</code></pre>
<p>would yield</p>
<pre><code> 2</code></pre>
<p>Check for the index value of last element</p>
<pre><code> echo '["one","two","three"]' | jsonrange -values -last</code></pre>
<p>would yield</p>
<pre><code> "three"</code></pre>
<p>Limitting the number of items returned</p>
<pre><code> echo '[10,20,30,40,50]' | %!s(MISSING) -limit 2</code></pre>
<p>would yield</p>
<pre><code> 1
2</code></pre>
<p>Limitting the number of values returned</p>
<pre><code> echo '[10,20,30,40,50]' | %!s(MISSING) -values -limit 2</code></pre>
<p>would yield</p>
<pre><code> 10
20</code></pre>
<p>jsonrange 1.2.12</p>
</section>
<footer>
<span><h1><A href="http://caltech.edu">Caltech</a></h1></span>
<span>© 2023 <a href="https://www.library.caltech.edu/copyright">Caltech library</a></span>
<address>1200 E California Blvd, Mail Code 1-32, Pasadena, CA 91125-3200</address>
<span>Phone: <a href="tel:+1-626-395-3405">(626)395-3405</a></span>
<span><a href="mailto:[email protected]">Email Us</a></span>
<a class="cl-hide" href="sitemap.xml">Site Map</a>
</footer>
</body>
</html>