summaryrefslogtreecommitdiffstats
path: root/manual/v1.4/index.html
diff options
context:
space:
mode:
Diffstat (limited to 'manual/v1.4/index.html')
-rw-r--r--manual/v1.4/index.html42
1 files changed, 21 insertions, 21 deletions
diff --git a/manual/v1.4/index.html b/manual/v1.4/index.html
index fe316b39..578491ac 100644
--- a/manual/v1.4/index.html
+++ b/manual/v1.4/index.html
@@ -130,8 +130,8 @@ simpler:</p>
<p>jq filters run on a stream of JSON data. The input to jq is
parsed as a sequence of whitespace-separated JSON values which
are passed through the provided filter one at a time. The
-output(s) of the filter are written to standard out, again as a
-sequence of whitespace-separated JSON data.</p>
+output(s) of the filter are written to standard output, as a
+sequence of newline-separated JSON data.</p>
<p>Note: it is important to mind the shell's quoting rules. As a
general rule it's best to always quote (with single-quote
characters) the jq program, as too many characters with special
@@ -438,16 +438,15 @@ object.</p>
</h3>
<p>You can also look up fields of an object using syntax like
<code>.["foo"]</code> (<code>.foo</code> above is a shorthand version of this). This
-one works for arrays as well, if the key is an
-integer. Arrays are zero-based (like javascript), so <code>.[2]</code>
-returns the third element of the array.</p>
+one works for arrays as well, if the key is an integer. Arrays
+are zero-based, so <code>.[2]</code> returns the third element of the array.</p>
<p>The <code>.[10:15]</code> syntax can be used to return a subarray of an
array or substring of a string. The array returned by
<code>.[10:15]</code> will be of length 5, containing the elements from
index 10 (inclusive) to index 15 (exclusive). Either index may
be negative (in which case it counts backwards from the end of
the array), or omitted (in which case it refers to the start
-or end of the array).</p>
+or end of the array). Indices are zero-based.</p>
<p>The <code>?</code> "operator" can also be used with the slice operator,
as in <code>.[10:15]?</code>, which outputs values where the inputs are
slice-able.</p>
@@ -795,7 +794,7 @@ element of the input array.</p>
strings, booleans, arrays, objects (which in JSON-speak are
hashes with only string keys), and "null".</p>
<p>Booleans, null, strings and numbers are written the same way as
-in javascript. Just like everything else in jq, these simple
+in JSON. Just like everything else in jq, these simple
values take an input and produce an output - <code>42</code> is a valid jq
expression that takes an input, ignores it, and returns 42
instead.</p>
@@ -3814,23 +3813,24 @@ input's <code>.foo</code> field to each element of the array.</p>
</section>
- <section id="Reduce">
+ <section id="reduce">
<h3>
- Reduce
+ <code>reduce</code>
</h3>
- <p>The <code>reduce</code> syntax in jq allows you to combine all of the
-results of an expression by accumulating them into a single
-answer. As an example, we'll pass <code>[3,2,1]</code> to this expression:</p>
+ <p>The <code>reduce</code> syntax allows you to combine all of the results of
+an expression by accumulating them into a single answer.
+The form is <code>reduce EXP as $var (INIT; UPDATE)</code>.
+As an example, we'll pass <code>[1,2,3]</code> to this expression:</p>
<pre><code>reduce .[] as $item (0; . + $item)
</code></pre>
<p>For each result that <code>.[]</code> produces, <code>. + $item</code> is run to
-accumulate a running total, starting from 0. In this
-example, <code>.[]</code> produces the results 3, 2, and 1, so the
-effect is similar to running something like this:</p>
-<pre><code>0 | (3 as $item | . + $item) |
- (2 as $item | . + $item) |
- (1 as $item | . + $item)
+accumulate a running total, starting from 0 as the input value.
+In this example, <code>.[]</code> produces the results <code>1</code>, <code>2</code>, and <code>3</code>,
+so the effect is similar to running something like this:</p>
+<pre><code>0 | 1 as $item | . + $item |
+ 2 as $item | . + $item |
+ 3 as $item | . + $item
</code></pre>
@@ -3844,14 +3844,14 @@ effect is similar to running something like this:</p>
<table>
<tr><th></th><td class="jqprogram">jq 'reduce .[] as $item (0; . + $item)'</td></tr>
- <tr><th>Input</th><td>[10,2,5,3]</td></tr>
+ <tr><th>Input</th><td>[1,2,3,4,5]</td></tr>
<tr>
<th>Output</th>
- <td>20</td>
+ <td>15</td>
</tr>
</table>
@@ -4168,7 +4168,7 @@ that we did before:</p>
"Defining Functions" : "DefiningFunctions",
- "Reduce" : "Reduce",
+ "reduce" : "reduce",
"Advanced features" : "Advancedfeatures"
,