docs update
This commit is contained in:
1 parent
a745594739
commit
21b7d34929
20 files changed
+554
-189
No files matched your search
@@ -1,95 +0,0 @@
|
||||
@charset "utf-8";
|
||||
|
||||
/* HTML resets */
|
||||
body, html, div, p, img, h1, h2, h3, h4, h5, h6, ol, ul, li { margin: 0; padding: 0; font-weight: normal; font-size: 100%; outline: none; border: none;}
|
||||
|
||||
/* HTML5 block elements */
|
||||
header, section, article, footer, aside, nav { display: block; }
|
||||
|
||||
/* Put your styles below here */
|
||||
#wrapper { margin: 0 auto; width: 660px; }
|
||||
|
||||
body { font-family: "Helvetica Neue", Helvetica, Arial, Geneva, sans-serif; }
|
||||
|
||||
header {
|
||||
margin-top: 5em;
|
||||
|
||||
#logo {
|
||||
width: 145px;
|
||||
height: 145px;
|
||||
margin: 0 auto;
|
||||
-moz-border-radius: 72px;
|
||||
-webkit-border-radius: 72px;
|
||||
background-color: black;
|
||||
|
||||
a {
|
||||
position: absolute;
|
||||
margin: 1em 0 0em 1.5em;
|
||||
color: white;
|
||||
text-align: center;
|
||||
text-transform: lowercase;
|
||||
text-decoration: none;
|
||||
font-weight: 100;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#navigation {
|
||||
margin: 5em 0;
|
||||
text-transform: lowercase;
|
||||
text-align: center;
|
||||
font-style: italic;
|
||||
font-size: 0.8em;
|
||||
li:not(:last-child):after { content: " /"; }
|
||||
|
||||
a { color: black; text-decoration: none; }
|
||||
a:hover { text-decoration: underline; }
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
nav li { display: inline; list-style-type: none; }
|
||||
|
||||
#breadcrumbs, footer { color: gray; font-size: 0.7em; }
|
||||
|
||||
#breadcrumbs {
|
||||
li:not(:last-child):after { content: " ➔";}
|
||||
border-top: 1px solid lightgray;
|
||||
padding-top:5px;
|
||||
a { color: inherit; }
|
||||
}
|
||||
|
||||
#sub-navigation{
|
||||
font-size: 0.8em;
|
||||
li { display: block; margin-bottom: 5px; }
|
||||
}
|
||||
|
||||
nav, footer { margin: 1em 0; }
|
||||
|
||||
/* Typesetting */
|
||||
h1, h2, h3, h4, h5, h6 { margin: 1.25em 0; }
|
||||
|
||||
h1 { font-size: 2em; }
|
||||
h2 { font-size: 1.6em; }
|
||||
h3 { font-size: 1.4em; }
|
||||
h4 { font-size: 1.2em; }
|
||||
h5 { font-size: 1em; }
|
||||
h6 { font-size: 0.9em; }
|
||||
|
||||
a { color: #256ec4; }
|
||||
p { font-size: 0.8em; line-height: 140%; margin-bottom: 10px; color: #333;}
|
||||
|
||||
/* Floating the Magic template */
|
||||
.magic article {
|
||||
width: 450px;
|
||||
float: left;
|
||||
border-right: 1px solid lightgray;
|
||||
margin-right: 14px;
|
||||
padding-right: 15px;
|
||||
}
|
||||
.magic aside {
|
||||
width: 180px;
|
||||
float: left
|
||||
}
|
||||
.clear{ clear: both; }
|
||||
+43
-17
@@ -53,25 +53,51 @@
|
||||
<h1>Download jq</h1>
|
||||
|
||||
|
||||
<p>jq is written in C and has no runtime dependencies, so it should be possible to build it for nearly any platform. Prebuilt binaries are available for Linux (64-bit x86) and OS X.</p>
|
||||
<p>jq is written in C and has no runtime dependencies, so it should be possible to build it for nearly any platform. Prebuilt binaries are available for Linux, OS X and Windows.</p>
|
||||
|
||||
<ul>
|
||||
<li><a href='linux_x86_64/jq'>Download binary for 64-bit Linux</a></li>
|
||||
|
||||
<li><a href='osx_64/jq'>Download binary for OS X</a> (or use <a href='http://mxcl.github.com/homebrew/'>homebrew</a>: <code>brew install jq</code>)</li>
|
||||
|
||||
<li><a href='source/jq.tgz'>Download source</a></li>
|
||||
</ul>
|
||||
|
||||
<p>The binaries should just run, but you may need to make them executable first using:</p>
|
||||
|
||||
<pre><code>chmod +x jq</code></pre>
|
||||
<p>The binaries should just run, but on OS X and Linux you may need to make them executable first using <code>chmod +x jq</code>.</p>
|
||||
|
||||
<p>jq is licensed under the MIT license. For all of the gory details, read the file <code>COPYING</code> in the source distribution.</p>
|
||||
|
||||
<h1 id='hacking_on_jq'>Hacking on jq</h1>
|
||||
<h3 id='linux'>Linux</h3>
|
||||
|
||||
<p>If you want to work on jq, grab the source from <a href='https://github.com/stedolan/jq'>https://github.com/stedolan/jq</a>.</p>
|
||||
<ul>
|
||||
<li>
|
||||
<p>Binaries for <a href='linux64/jq'>64-bit</a> or <a href='linux32/jq'>32-bit</a> systems.</p>
|
||||
</li>
|
||||
|
||||
<li>
|
||||
<p>For Arch users, a PKGBUILD for jq-1.1 is in the <a href='https://aur.archlinux.org/packages.php?ID=63849'>AUR</a>, as well as a PKGBUILD for the HEAD of master (<a href='https://aur.archlinux.org/packages.php?ID=63850'>jq-git</a>). You can install them using <a href='https://wiki.archlinux.org/index.php/Yaourt'>Yaourt</a> or manually by following instructions on <a href='https://wiki.archlinux.org/index.php/Arch_UseRepository'>Arch Linux’s Wiki</a>.</p>
|
||||
</li>
|
||||
|
||||
<li>
|
||||
<p>Debian/Ubuntu packages are coming Real Soon Now.</p>
|
||||
</li>
|
||||
</ul>
|
||||
|
||||
<h3 id='os_x'>OS X</h3>
|
||||
|
||||
<ul>
|
||||
<li>
|
||||
<p><code>brew install jq</code> using <a href='http://mxcl.github.com/homebrew/'>homebrew</a></p>
|
||||
</li>
|
||||
|
||||
<li>
|
||||
<p>Or, grab prebuilt <a href='osx64/jq'>64-bit binaries</a> or <a href='osx32/jq'>32-bit binaries</a></p>
|
||||
</li>
|
||||
</ul>
|
||||
|
||||
<h3 id='windows'>Windows</h3>
|
||||
|
||||
<ul>
|
||||
<li>Executables for <a href='win64/jq'>64-bit</a> or <a href='win32/jq'>32-bit</a></li>
|
||||
</ul>
|
||||
|
||||
<h3 id='from_source_on_linux_or_os_x'>From source on Linux or OS X</h3>
|
||||
|
||||
<pre><code>git clone https://github.com/stedolan/jq.git
|
||||
cd jq
|
||||
make && sudo make install</code></pre>
|
||||
|
||||
<p>To build it from a git clone, you’ll need to install a few packages first:</p>
|
||||
|
||||
@@ -87,13 +113,13 @@
|
||||
<li><a href='http://www.gnu.org/software/make'>Make</a></li>
|
||||
</ul>
|
||||
|
||||
<p>Most of these aren’t necessary if you’re just trying to compile jq from the released tarball - that version has the non-platform-specific build steps already done, so you’ll only need a C compiler and <code>make</code> to finish it off.</p>
|
||||
<p>For Linux systems, these will all be in your system’s package manager, and if you do development on the machine they’re most likely already installed.</p>
|
||||
|
||||
<p>For Linux systems, these will all be in your system’s package manager, and if you do development on the machine they’re most likely already installed. I have no idea how to get these installed on OS X, you’re on your own there.</p>
|
||||
<p>On OS X, these are all included in Apple’s command line tools, which can be installed from <a href='http://developer.apple.com/technologies/tools/'>Xcode</a>. However, you may find that you need a newer version of Bison than the one provided by Apple. This can be found in <a href='http://mxcl.github.com/homebrew/'>Homebrew</a> or <a href='http://macports.org/'>MacPorts</a>.</p>
|
||||
|
||||
<p><code>flex</code> and <code>bison</code> are used to generate the lexer and parser for jq, and some python scripts generate the UTF8 encoding tables needed for JSON parsing.</p>
|
||||
|
||||
<h2 id='building_the_documentation'>Building the documentation</h2>
|
||||
<h4 id='building_the_documentation'>Building the documentation</h4>
|
||||
|
||||
<p>jq’s documentation is compiled into static HTML using <a href='http://www.tinytree.info'>Bonsai</a>. To view the documentation locally, run <code>rake serve</code> from the docs/ subdirectory.</p>
|
||||
|
||||
|
||||
Executable
BIN
Binary file not shown.
Executable
BIN
Binary file not shown.
Executable
BIN
Binary file not shown.
Executable
BIN
Binary file not shown.
Binary file not shown.
Executable
BIN
Binary file not shown.
Executable
BIN
Binary file not shown.
Executable
BIN
Binary file not shown.
Executable
BIN
Binary file not shown.
Binary file not shown.
Binary file not shown.
Executable
BIN
Binary file not shown.
Executable
BIN
Binary file not shown.
Executable
BIN
Binary file not shown.
Executable
BIN
Binary file not shown.
+14
-7
@@ -55,12 +55,12 @@
|
||||
<p>jq is a lightweight and flexible command-line JSON processor.</p>
|
||||
<div class="btn-group" style="float:right">
|
||||
<a class="btn btn-primary dropdown-toggle" data-toggle="dropdown" href="#">
|
||||
Download jq-1.1
|
||||
Download jq-1.2
|
||||
<span class="caret"></span>
|
||||
</a>
|
||||
<ul class="dropdown-menu">
|
||||
<li><a href="/jq/download/linux_x86_64/jq">Linux (x86_64)</a></li>
|
||||
<li><a href="/jq/download/osx_64/jq">OS X (64-bit)</a></li>
|
||||
<li><a href="/jq/download/linux64/jq">Linux (64-bit)</a></li>
|
||||
<li><a href="/jq/download/osx64/jq">OS X (64-bit)</a></li>
|
||||
<li><a href="/jq/download">Other platforms and source</a></li>
|
||||
</ul>
|
||||
</div>
|
||||
@@ -71,12 +71,19 @@
|
||||
</div>
|
||||
|
||||
<div class="row" id="multiblurb">
|
||||
<div class="span4"><p>jq is like <code>sed</code> for JSON data - you can use it to slice and filter and map and transform structured data with the same ease that <code>sed</code>, <code>awk</code>, <code>grep</code> and friends let you play with text.</p></div>
|
||||
<div class="span4"><p>jq is written in portable C, and it has zero runtime dependencies. You can download a single binary, <code>scp</code> it to a far away machine, and expect it to work.</p></div>
|
||||
<div class="span4"><p>jq can mangle the data format that you have into the one that you want with very little effort, and the program to do so is often shorter and simpler than you’d expect.</p></div>
|
||||
<div class="span4"><p>jq is like <code>sed</code> for JSON data – you can use it to slice and filter
|
||||
and map and transform structured data with the same ease that <code>sed</code>,
|
||||
<code>awk</code>, <code>grep</code> and friends let you play with text.</p></div>
|
||||
<div class="span4"><p>jq is written in portable C, and it has zero runtime
|
||||
dependencies. You can download a single binary, <code>scp</code> it to a far away
|
||||
machine, and expect it to work.</p></div>
|
||||
<div class="span4"><p>jq can mangle the data format that you have into the one that you
|
||||
want with very little effort, and the program to do so is often
|
||||
shorter and simpler than you’d expect.</p></div>
|
||||
</div>
|
||||
<div class="row" style="text-align:center; margin-top: 30px">
|
||||
<p>Go read the <a href='tutorial'>tutorial</a> for more, or the <a href='manual'>manual</a> for <em>way</em> more.</p>
|
||||
<p>Go read the <a href='tutorial'>tutorial</a> for more, or the <a href='manual'>manual</a>
|
||||
for <em>way</em> more.</p>
|
||||
</div>
|
||||
</div>
|
||||
<footer>
|
||||
|
||||
+14
-7
@@ -55,12 +55,12 @@
|
||||
<p>jq is a lightweight and flexible command-line JSON processor.</p>
|
||||
<div class="btn-group" style="float:right">
|
||||
<a class="btn btn-primary dropdown-toggle" data-toggle="dropdown" href="#">
|
||||
Download jq-1.1
|
||||
Download jq-1.2
|
||||
<span class="caret"></span>
|
||||
</a>
|
||||
<ul class="dropdown-menu">
|
||||
<li><a href="/jq/download/linux_x86_64/jq">Linux (x86_64)</a></li>
|
||||
<li><a href="/jq/download/osx_64/jq">OS X (64-bit)</a></li>
|
||||
<li><a href="/jq/download/linux64/jq">Linux (64-bit)</a></li>
|
||||
<li><a href="/jq/download/osx64/jq">OS X (64-bit)</a></li>
|
||||
<li><a href="/jq/download">Other platforms and source</a></li>
|
||||
</ul>
|
||||
</div>
|
||||
@@ -71,12 +71,19 @@
|
||||
</div>
|
||||
|
||||
<div class="row" id="multiblurb">
|
||||
<div class="span4"><p>jq is like <code>sed</code> for JSON data - you can use it to slice and filter and map and transform structured data with the same ease that <code>sed</code>, <code>awk</code>, <code>grep</code> and friends let you play with text.</p></div>
|
||||
<div class="span4"><p>jq is written in portable C, and it has zero runtime dependencies. You can download a single binary, <code>scp</code> it to a far away machine, and expect it to work.</p></div>
|
||||
<div class="span4"><p>jq can mangle the data format that you have into the one that you want with very little effort, and the program to do so is often shorter and simpler than you’d expect.</p></div>
|
||||
<div class="span4"><p>jq is like <code>sed</code> for JSON data – you can use it to slice and filter
|
||||
and map and transform structured data with the same ease that <code>sed</code>,
|
||||
<code>awk</code>, <code>grep</code> and friends let you play with text.</p></div>
|
||||
<div class="span4"><p>jq is written in portable C, and it has zero runtime
|
||||
dependencies. You can download a single binary, <code>scp</code> it to a far away
|
||||
machine, and expect it to work.</p></div>
|
||||
<div class="span4"><p>jq can mangle the data format that you have into the one that you
|
||||
want with very little effort, and the program to do so is often
|
||||
shorter and simpler than you’d expect.</p></div>
|
||||
</div>
|
||||
<div class="row" style="text-align:center; margin-top: 30px">
|
||||
<p>Go read the <a href='tutorial'>tutorial</a> for more, or the <a href='manual'>manual</a> for <em>way</em> more.</p>
|
||||
<p>Go read the <a href='tutorial'>tutorial</a> for more, or the <a href='manual'>manual</a>
|
||||
for <em>way</em> more.</p>
|
||||
</div>
|
||||
</div>
|
||||
<footer>
|
||||
|
||||
+483
-63
@@ -137,6 +137,16 @@
|
||||
|
||||
"`tostring`" : "tostring",
|
||||
|
||||
"`sort, sort_by`" : "sortsort_by",
|
||||
|
||||
"`group_by`" : "group_by",
|
||||
|
||||
"`min`, `max`, `min_by`, `max_by`" : "minmaxmin_bymax_by",
|
||||
|
||||
"`unique`" : "unique",
|
||||
|
||||
"`contains`" : "contains",
|
||||
|
||||
"String interpolation - `\\(foo)`" : "Stringinterpolationfoo",
|
||||
|
||||
"Builtin operators and functions" : "Builtinoperatorsandfunctions"
|
||||
@@ -147,6 +157,8 @@
|
||||
|
||||
"if-then-else" : "ifthenelse",
|
||||
|
||||
"`>, >=, <=, <`" : "",
|
||||
|
||||
"and/or/not" : "andornot",
|
||||
|
||||
"Alternative operator - `//`" : "Alternativeoperator",
|
||||
@@ -195,7 +207,23 @@
|
||||
</div>
|
||||
<div class="span9">
|
||||
<h1>jq Manual</h1>
|
||||
<p>A jq program is a “filter”: it takes an input, and produces an output. There are a lot of builtin filters for extracting a particular field of an object, or converting a number to a string, or various other standard tasks.</p><p>Filters can be combined in various ways - you can pipe the output of one filter into another filter, or collect the output of a filter into an array.</p><p>Some filters produce multiple results, for instance there’s one that produces all the elements of its input array. Piping that filter into a second runs the second filter for each element of the array. Generally, things that would be done with loops and iteration in other languages are just done by gluing filters together in jq.</p><p>It’s important to remember that every filter has an input and an output. Even literals like “hello” or 42 are filters - they take an input but always produce the same literal as output. Operations that combine two filters, like addition, generally feed the same input to both and combine the results. So, you can implement an averaging filter as <code>add / length</code> - feeding the input array both to the <code>add</code> filter and the <code>length</code> filter and dividing the results.</p><p>But that’s getting ahead of ourselves. :) Let’s start with something simpler:</p>
|
||||
<p>A jq program is a “filter”: it takes an input, and produces an
|
||||
output. There are a lot of builtin filters for extracting a
|
||||
particular field of an object, or converting a number to a string,
|
||||
or various other standard tasks.</p><p>Filters can be combined in various ways – you can pipe the output of
|
||||
one filter into another filter, or collect the output of a filter
|
||||
into an array.</p><p>Some filters produce multiple results, for instance there’s one that
|
||||
produces all the elements of its input array. Piping that filter
|
||||
into a second runs the second filter for each element of the
|
||||
array. Generally, things that would be done with loops and iteration
|
||||
in other languages are just done by gluing filters together in jq.</p><p>It’s important to remember that every filter has an input and an
|
||||
output. Even literals like “hello” or 42 are filters – they take an
|
||||
input but always produce the same literal as output. Operations that
|
||||
combine two filters, like addition, generally feed the same input to
|
||||
both and combine the results. So, you can implement an averaging
|
||||
filter as <code>add / length</code> – feeding the input array both to the <code>add</code>
|
||||
filter and the <code>length</code> filter and dividing the results.</p><p>But that’s getting ahead of ourselves. :) Let’s start with something
|
||||
simpler:</p>
|
||||
|
||||
<section id="Invokingjq">
|
||||
<h2>Invoking jq</h2>
|
||||
@@ -203,43 +231,51 @@
|
||||
|
||||
<p>You can affect how jq reads and writes its input and output using some command-line options:</p>
|
||||
|
||||
<ul>
|
||||
<li>
|
||||
<p><code>--slurp</code>/<code>-s</code></p>
|
||||
<p>* <code>--slurp</code>/<code>-s</code>:</p>
|
||||
|
||||
<p>Instead of running the filter for each JSON object in the input, read the entire input stream into a large array and run the filter just once.</p>
|
||||
</li>
|
||||
<pre><code>Instead of running the filter for each JSON object in the
|
||||
input, read the entire input stream into a large array and run
|
||||
the filter just once.</code></pre>
|
||||
|
||||
<li>
|
||||
<p><code>--raw-input</code>/<code>-R</code></p>
|
||||
<p>* <code>--raw-input</code>/<code>-R</code>:</p>
|
||||
|
||||
<p>Don’t parse the input as JSON. Instead, each line of text is passed to the filter as a string. If combined with <code>--slurp</code>, then the entire input is passed to the filter as a single long string.</p>
|
||||
</li>
|
||||
<pre><code>Don't parse the input as JSON. Instead, each line of text is
|
||||
passed to the filter as a string. If combined with `--slurp`,
|
||||
then the entire input is passed to the filter as a single long
|
||||
string.</code></pre>
|
||||
|
||||
<li>
|
||||
<p><code>--null-input</code>/<code>-n</code></p>
|
||||
<p>* <code>--null-input</code>/<code>-n</code>:</p>
|
||||
|
||||
<p>Don’t read any input at all! Instead, the filter is run once using <code>null</code> as the input. This is useful when using jq as a simple calculator or to construct JSON data from scratch.</p>
|
||||
</li>
|
||||
<pre><code>Don't read any input at all! Instead, the filter is run once
|
||||
using `null` as the input. This is useful when using jq as a
|
||||
simple calculator or to construct JSON data from scratch.</code></pre>
|
||||
|
||||
<li>
|
||||
<p><code>--compact-output</code> / <code>-c</code></p>
|
||||
<p>* <code>--compact-output</code> / <code>-c</code>:</p>
|
||||
|
||||
<p>By default, jq pretty-prints JSON output. Using this option will result in more compact output by instead putting each JSON object on a single line.</p>
|
||||
</li>
|
||||
<pre><code>By default, jq pretty-prints JSON output. Using this option
|
||||
will result in more compact output by instead putting each
|
||||
JSON object on a single line.</code></pre>
|
||||
|
||||
<li>
|
||||
<p><code>--ascii-output</code> / <code>-a</code></p>
|
||||
<p>* <code>--colour-output</code> / <code>-C</code> and <code>--monochrome-output</code> / <code>-M</code>:</p>
|
||||
|
||||
<p>jq usually outputs non-ASCII Unicode codepoints as UTF-8, even if the input specified them as escape sequences (like “\u03bc”). Using this option, you can force jq to produce pure ASCII output with every non-ASCII character replaced with the equivalent escape sequence.</p>
|
||||
</li>
|
||||
<pre><code>By default, jq outputs colored JSON if writing to a
|
||||
terminal. You can force it to produce color even if writing to
|
||||
a pipe or a file using `-C`, and disable color with `-M`.</code></pre>
|
||||
|
||||
<li>
|
||||
<p><code>--raw-output</code> / <code>-r</code></p>
|
||||
<p>* <code>--ascii-output</code> / <code>-a</code>:</p>
|
||||
|
||||
<p>With this option, if the filter’s result is a string then it will be written directly to standard output rather than being formatted as a JSON string with quotes. This can be useful for making jq filters talk to non-JSON-based systems.</p>
|
||||
</li>
|
||||
</ul>
|
||||
<pre><code>jq usually outputs non-ASCII Unicode codepoints as UTF-8, even
|
||||
if the input specified them as escape sequences (like
|
||||
"\u03bc"). Using this option, you can force jq to produce pure
|
||||
ASCII output with every non-ASCII character replaced with the
|
||||
equivalent escape sequence.</code></pre>
|
||||
|
||||
<p>* <code>--raw-output</code> / <code>-r</code>:</p>
|
||||
|
||||
<pre><code>With this option, if the filter's result is a string then it
|
||||
will be written directly to standard output rather than being
|
||||
formatted as a JSON string with quotes. This can be useful for
|
||||
making jq filters talk to non-JSON-based systems.</code></pre>
|
||||
|
||||
</section>
|
||||
|
||||
@@ -409,7 +445,7 @@
|
||||
|
||||
<table class="manual-example">
|
||||
<tr><th></th><td class="jqprogram">jq '.[]'</td></tr>
|
||||
<tr><th>Input</th><td>[{name":"JSON", "good":true}, {"name":"XML", "good":false}]</td></tr>
|
||||
<tr><th>Input</th><td>[{"name":"JSON", "good":true}, {"name":"XML", "good":false}]</td></tr>
|
||||
|
||||
|
||||
<tr>
|
||||
@@ -524,7 +560,7 @@
|
||||
|
||||
<th>Output</th>
|
||||
|
||||
<td>"d"</td>
|
||||
<td>"e"</td>
|
||||
</tr>
|
||||
|
||||
<tr>
|
||||
@@ -563,7 +599,7 @@
|
||||
|
||||
<table class="manual-example">
|
||||
<tr><th></th><td class="jqprogram">jq '.[] | .name'</td></tr>
|
||||
<tr><th>Input</th><td>[{name":"JSON", "good":true}, {"name":"XML", "good":false}]</td></tr>
|
||||
<tr><th>Input</th><td>[{"name":"JSON", "good":true}, {"name":"XML", "good":false}]</td></tr>
|
||||
|
||||
|
||||
<tr>
|
||||
@@ -772,17 +808,12 @@
|
||||
<tr><th></th><td class="jqprogram">jq '.a + 1'</td></tr>
|
||||
<tr><th>Input</th><td>{"a": 7}</td></tr>
|
||||
|
||||
<tr>
|
||||
<th>Output</th>
|
||||
<td><i>none</i></td>
|
||||
</tr>
|
||||
|
||||
|
||||
<tr>
|
||||
|
||||
<th>Output</th>
|
||||
|
||||
<td>{"a": 8}</td>
|
||||
<td>8</td>
|
||||
</tr>
|
||||
|
||||
|
||||
@@ -997,12 +1028,14 @@
|
||||
|
||||
<p>The keys are sorted “alphabetically”, by unicode codepoint order. This is not an order that makes particular sense in any particular language, but you can count on it being the same for any two objects with the same set of keys, regardless of locale settings.</p>
|
||||
|
||||
<p>When <code>keys</code> is given an array, it returns the valid indices for that array: the integers from 0 to length-1.</p>
|
||||
|
||||
|
||||
<div>
|
||||
|
||||
<a data-toggle="collapse" href="#example13">
|
||||
<i class="icon-chevron-right"></i>
|
||||
Example
|
||||
Examples
|
||||
</a>
|
||||
<div id="example13" class="collapse">
|
||||
|
||||
@@ -1022,6 +1055,21 @@
|
||||
|
||||
</table>
|
||||
|
||||
<table class="manual-example">
|
||||
<tr><th></th><td class="jqprogram">jq 'keys'</td></tr>
|
||||
<tr><th>Input</th><td>[42,3,35]</td></tr>
|
||||
|
||||
|
||||
<tr>
|
||||
|
||||
<th>Output</th>
|
||||
|
||||
<td>[0,1,2]</td>
|
||||
</tr>
|
||||
|
||||
|
||||
</table>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -1034,7 +1082,7 @@
|
||||
</h3>
|
||||
<p>The function <code>select(foo)</code> produces its input unchanged if <code>foo</code> returns true for that input, and produces no output otherwise.</p>
|
||||
|
||||
<p>It’s useful for filtering lists: <code>[1,2,3] | select(. >= 2)</code> will give you <code>[3]</code>.</p>
|
||||
<p>It’s useful for filtering lists: <code>[1,2,3] | map(select(. >= 2))</code> will give you <code>[3]</code>.</p>
|
||||
|
||||
|
||||
<div>
|
||||
@@ -1047,7 +1095,7 @@
|
||||
|
||||
|
||||
<table class="manual-example">
|
||||
<tr><th></th><td class="jqprogram">jq 'select(. >= 2)'</td></tr>
|
||||
<tr><th></th><td class="jqprogram">jq 'map(select(. >= 2))'</td></tr>
|
||||
<tr><th>Input</th><td>[1,5,3,0,7]</td></tr>
|
||||
|
||||
|
||||
@@ -1094,7 +1142,14 @@
|
||||
|
||||
<th>Output</th>
|
||||
|
||||
<td>12</td>
|
||||
<td>1</td>
|
||||
</tr>
|
||||
|
||||
<tr>
|
||||
|
||||
<th></th>
|
||||
|
||||
<td>2</td>
|
||||
</tr>
|
||||
|
||||
|
||||
@@ -1187,7 +1242,7 @@
|
||||
|
||||
<th>Output</th>
|
||||
|
||||
<td>abc</td>
|
||||
<td>"abc"</td>
|
||||
</tr>
|
||||
|
||||
|
||||
@@ -1254,7 +1309,14 @@
|
||||
|
||||
<th>Output</th>
|
||||
|
||||
<td>11</td>
|
||||
<td>1</td>
|
||||
</tr>
|
||||
|
||||
<tr>
|
||||
|
||||
<th></th>
|
||||
|
||||
<td>1</td>
|
||||
</tr>
|
||||
|
||||
|
||||
@@ -1316,6 +1378,303 @@
|
||||
|
||||
</section>
|
||||
|
||||
<section id="sortsort_by">
|
||||
<h3>
|
||||
<p><code>sort, sort_by</code></p>
|
||||
|
||||
</h3>
|
||||
<p>The <code>sort</code> functions sorts its input, which must be an array. Values are sorted in the following order:</p>
|
||||
|
||||
<ul>
|
||||
<li><code>null</code></li>
|
||||
|
||||
<li><code>false</code></li>
|
||||
|
||||
<li><code>true</code></li>
|
||||
|
||||
<li>numbers</li>
|
||||
|
||||
<li>strings, in alphabetical order (by unicode codepoint value)</li>
|
||||
|
||||
<li>arrays, in lexical order</li>
|
||||
|
||||
<li>objects</li>
|
||||
</ul>
|
||||
|
||||
<p>The ordering for objects is a little complex: first they’re compared by comparing their sets of keys (as arrays in sorted order), and if their keys are equal then the values are compared key by key.</p>
|
||||
|
||||
<p><code>sort_by</code> may be used to sort by a particular field of an object, or by applying any jq filter. <code>sort_by(foo)</code> compares two elements by comparing the result of <code>foo</code> on each element.</p>
|
||||
|
||||
|
||||
<div>
|
||||
|
||||
<a data-toggle="collapse" href="#example20">
|
||||
<i class="icon-chevron-right"></i>
|
||||
Examples
|
||||
</a>
|
||||
<div id="example20" class="collapse">
|
||||
|
||||
|
||||
<table class="manual-example">
|
||||
<tr><th></th><td class="jqprogram">jq 'sort'</td></tr>
|
||||
<tr><th>Input</th><td>[8,3,null,6]</td></tr>
|
||||
|
||||
|
||||
<tr>
|
||||
|
||||
<th>Output</th>
|
||||
|
||||
<td>[null,3,6,8]</td>
|
||||
</tr>
|
||||
|
||||
|
||||
</table>
|
||||
|
||||
<table class="manual-example">
|
||||
<tr><th></th><td class="jqprogram">jq 'sort_by(.foo)'</td></tr>
|
||||
<tr><th>Input</th><td>[{"foo":4, "bar":10}, {"foo":3, "bar":100}, {"foo":2, "bar":1}]</td></tr>
|
||||
|
||||
|
||||
<tr>
|
||||
|
||||
<th>Output</th>
|
||||
|
||||
<td>[{"foo":2, "bar":1}, {"foo":3, "bar":100}, {"foo":4, "bar":10}]</td>
|
||||
</tr>
|
||||
|
||||
|
||||
</table>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</section>
|
||||
|
||||
<section id="group_by">
|
||||
<h3>
|
||||
<p><code>group_by</code></p>
|
||||
|
||||
</h3>
|
||||
<p><code>group_by(.foo)</code> takes as input an array, groups the elements having the same <code>.foo</code> field into separate arrays, and produces all of these arrays as elements of a larger array, sorted by the value of the <code>.foo</code> field.</p>
|
||||
|
||||
<p>Any jq expression, not just a field access, may be used in place of <code>.foo</code>. The sorting order is the same as described in the <code>sort</code> function above.</p>
|
||||
|
||||
|
||||
<div>
|
||||
|
||||
<a data-toggle="collapse" href="#example21">
|
||||
<i class="icon-chevron-right"></i>
|
||||
Example
|
||||
</a>
|
||||
<div id="example21" class="collapse">
|
||||
|
||||
|
||||
<table class="manual-example">
|
||||
<tr><th></th><td class="jqprogram">jq 'group_by(.foo)'</td></tr>
|
||||
<tr><th>Input</th><td>[{"foo":1, "bar":10}, {"foo":3, "bar":100}, {"foo":1, "bar":1}]</td></tr>
|
||||
|
||||
|
||||
<tr>
|
||||
|
||||
<th>Output</th>
|
||||
|
||||
<td>[[{"foo":1, "bar":10}, {"foo":1, "bar":1}], [{"foo":3, "bar":100}]]</td>
|
||||
</tr>
|
||||
|
||||
|
||||
</table>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</section>
|
||||
|
||||
<section id="minmaxmin_bymax_by">
|
||||
<h3>
|
||||
<p><code>min</code>, <code>max</code>, <code>min_by</code>, <code>max_by</code></p>
|
||||
|
||||
</h3>
|
||||
<p>Find the minimum or maximum element of the input array. The <code>_by</code> versions allow you to specify a particular field or property to examine, e.g. <code>min_by(.foo)</code> finds the object with the smallest <code>foo</code> field.</p>
|
||||
|
||||
|
||||
<div>
|
||||
|
||||
<a data-toggle="collapse" href="#example22">
|
||||
<i class="icon-chevron-right"></i>
|
||||
Examples
|
||||
</a>
|
||||
<div id="example22" class="collapse">
|
||||
|
||||
|
||||
<table class="manual-example">
|
||||
<tr><th></th><td class="jqprogram">jq 'min'</td></tr>
|
||||
<tr><th>Input</th><td>[5,4,2,7]</td></tr>
|
||||
|
||||
|
||||
<tr>
|
||||
|
||||
<th>Output</th>
|
||||
|
||||
<td>2</td>
|
||||
</tr>
|
||||
|
||||
|
||||
</table>
|
||||
|
||||
<table class="manual-example">
|
||||
<tr><th></th><td class="jqprogram">jq 'max_by(.foo)'</td></tr>
|
||||
<tr><th>Input</th><td>[{"foo":1, "bar":14}, {"foo":2, "bar":3}]</td></tr>
|
||||
|
||||
|
||||
<tr>
|
||||
|
||||
<th>Output</th>
|
||||
|
||||
<td>{"foo":2, "bar":3}</td>
|
||||
</tr>
|
||||
|
||||
|
||||
</table>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</section>
|
||||
|
||||
<section id="unique">
|
||||
<h3>
|
||||
<p><code>unique</code></p>
|
||||
|
||||
</h3>
|
||||
<p>The <code>unique</code> function takes as input an array and produces an array of the same elements, in sorted order, with duplicates removed.</p>
|
||||
|
||||
|
||||
<div>
|
||||
|
||||
<a data-toggle="collapse" href="#example23">
|
||||
<i class="icon-chevron-right"></i>
|
||||
Example
|
||||
</a>
|
||||
<div id="example23" class="collapse">
|
||||
|
||||
|
||||
<table class="manual-example">
|
||||
<tr><th></th><td class="jqprogram">jq 'unique'</td></tr>
|
||||
<tr><th>Input</th><td>[1,2,5,3,5,3,1,3]</td></tr>
|
||||
|
||||
|
||||
<tr>
|
||||
|
||||
<th>Output</th>
|
||||
|
||||
<td>[1,2,3,5]</td>
|
||||
</tr>
|
||||
|
||||
|
||||
</table>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</section>
|
||||
|
||||
<section id="contains">
|
||||
<h3>
|
||||
<p><code>contains</code></p>
|
||||
|
||||
</h3>
|
||||
<p>The filter <code>contains(b)</code> will produce true if b is completely contained within the input. A string B is contained in a string A if B is a substring of A. An array B is contained in an array A is all elements in B are contained in any element in A. An object B is contained in object A if all of the values in B are contained in the value in A with the same key. All other types are assumed to be contained in each other if they are equal.</p>
|
||||
|
||||
|
||||
<div>
|
||||
|
||||
<a data-toggle="collapse" href="#example24">
|
||||
<i class="icon-chevron-right"></i>
|
||||
Examples
|
||||
</a>
|
||||
<div id="example24" class="collapse">
|
||||
|
||||
|
||||
<table class="manual-example">
|
||||
<tr><th></th><td class="jqprogram">jq 'contains("bar")'</td></tr>
|
||||
<tr><th>Input</th><td>"foobar"</td></tr>
|
||||
|
||||
|
||||
<tr>
|
||||
|
||||
<th>Output</th>
|
||||
|
||||
<td>true</td>
|
||||
</tr>
|
||||
|
||||
|
||||
</table>
|
||||
|
||||
<table class="manual-example">
|
||||
<tr><th></th><td class="jqprogram">jq 'contains(["baz", "bar"])'</td></tr>
|
||||
<tr><th>Input</th><td>["foobar", "foobaz", "blarp"]</td></tr>
|
||||
|
||||
|
||||
<tr>
|
||||
|
||||
<th>Output</th>
|
||||
|
||||
<td>true</td>
|
||||
</tr>
|
||||
|
||||
|
||||
</table>
|
||||
|
||||
<table class="manual-example">
|
||||
<tr><th></th><td class="jqprogram">jq 'contains(["bazzzzz", "bar"])'</td></tr>
|
||||
<tr><th>Input</th><td>["foobar", "foobaz", "blarp"]</td></tr>
|
||||
|
||||
|
||||
<tr>
|
||||
|
||||
<th>Output</th>
|
||||
|
||||
<td>false</td>
|
||||
</tr>
|
||||
|
||||
|
||||
</table>
|
||||
|
||||
<table class="manual-example">
|
||||
<tr><th></th><td class="jqprogram">jq 'contains({foo: 12, bar: [{barp: 12}]})'</td></tr>
|
||||
<tr><th>Input</th><td>{"foo": 12, "bar":[1,2,{"barp":12, "blip":13}]}</td></tr>
|
||||
|
||||
|
||||
<tr>
|
||||
|
||||
<th>Output</th>
|
||||
|
||||
<td>true</td>
|
||||
</tr>
|
||||
|
||||
|
||||
</table>
|
||||
|
||||
<table class="manual-example">
|
||||
<tr><th></th><td class="jqprogram">jq 'contains({foo: 12, bar: [{barp: 15}]})'</td></tr>
|
||||
<tr><th>Input</th><td>{"foo": 12, "bar":[1,2,{"barp":12, "blip":13}]}</td></tr>
|
||||
|
||||
|
||||
<tr>
|
||||
|
||||
<th>Output</th>
|
||||
|
||||
<td>false</td>
|
||||
</tr>
|
||||
|
||||
|
||||
</table>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</section>
|
||||
|
||||
<section id="Stringinterpolationfoo">
|
||||
<h3>
|
||||
<p>String interpolation - <code>\(foo)</code></p>
|
||||
@@ -1326,11 +1685,11 @@
|
||||
|
||||
<div>
|
||||
|
||||
<a data-toggle="collapse" href="#example20">
|
||||
<a data-toggle="collapse" href="#example25">
|
||||
<i class="icon-chevron-right"></i>
|
||||
Example
|
||||
</a>
|
||||
<div id="example20" class="collapse">
|
||||
<div id="example25" class="collapse">
|
||||
|
||||
|
||||
<table class="manual-example">
|
||||
@@ -1371,11 +1730,11 @@
|
||||
|
||||
<div>
|
||||
|
||||
<a data-toggle="collapse" href="#example21">
|
||||
<a data-toggle="collapse" href="#example26">
|
||||
<i class="icon-chevron-right"></i>
|
||||
Example
|
||||
</a>
|
||||
<div id="example21" class="collapse">
|
||||
<div id="example26" class="collapse">
|
||||
|
||||
|
||||
<table class="manual-example">
|
||||
@@ -1387,7 +1746,28 @@
|
||||
|
||||
<th>Output</th>
|
||||
|
||||
<td>[true, true, false, false]</td>
|
||||
<td>true</td>
|
||||
</tr>
|
||||
|
||||
<tr>
|
||||
|
||||
<th></th>
|
||||
|
||||
<td>true</td>
|
||||
</tr>
|
||||
|
||||
<tr>
|
||||
|
||||
<th></th>
|
||||
|
||||
<td>false</td>
|
||||
</tr>
|
||||
|
||||
<tr>
|
||||
|
||||
<th></th>
|
||||
|
||||
<td>false</td>
|
||||
</tr>
|
||||
|
||||
|
||||
@@ -1414,11 +1794,11 @@
|
||||
|
||||
<div>
|
||||
|
||||
<a data-toggle="collapse" href="#example22">
|
||||
<a data-toggle="collapse" href="#example27">
|
||||
<i class="icon-chevron-right"></i>
|
||||
Example
|
||||
</a>
|
||||
<div id="example22" class="collapse">
|
||||
<div id="example27" class="collapse">
|
||||
|
||||
|
||||
<table class="manual-example">
|
||||
@@ -1447,6 +1827,45 @@ end'</td></tr>
|
||||
|
||||
</section>
|
||||
|
||||
<section id="">
|
||||
<h3>
|
||||
<p><code>>, >=, <=, <</code></p>
|
||||
|
||||
</h3>
|
||||
<p>The comparison operators <code>></code>, <code>>=</code>, <code><=</code>, <code><</code> return whether their left argument is greater than, greater than or equal to, less than or equal to or less than their right argument (respectively).</p>
|
||||
|
||||
<p>The ordering is the same as that described for <code>sort</code>, above.</p>
|
||||
|
||||
|
||||
<div>
|
||||
|
||||
<a data-toggle="collapse" href="#example28">
|
||||
<i class="icon-chevron-right"></i>
|
||||
Example
|
||||
</a>
|
||||
<div id="example28" class="collapse">
|
||||
|
||||
|
||||
<table class="manual-example">
|
||||
<tr><th></th><td class="jqprogram">jq '. < 5'</td></tr>
|
||||
<tr><th>Input</th><td>2</td></tr>
|
||||
|
||||
|
||||
<tr>
|
||||
|
||||
<th>Output</th>
|
||||
|
||||
<td>true</td>
|
||||
</tr>
|
||||
|
||||
|
||||
</table>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</section>
|
||||
|
||||
<section id="andornot">
|
||||
<h3>
|
||||
<p>and/or/not</p>
|
||||
@@ -1464,11 +1883,11 @@ not</code>.</p>
|
||||
|
||||
<div>
|
||||
|
||||
<a data-toggle="collapse" href="#example23">
|
||||
<a data-toggle="collapse" href="#example29">
|
||||
<i class="icon-chevron-right"></i>
|
||||
Examples
|
||||
</a>
|
||||
<div id="example23" class="collapse">
|
||||
<div id="example29" class="collapse">
|
||||
|
||||
|
||||
<table class="manual-example">
|
||||
@@ -1576,11 +1995,11 @@ not</code>.</p>
|
||||
|
||||
<div>
|
||||
|
||||
<a data-toggle="collapse" href="#example24">
|
||||
<a data-toggle="collapse" href="#example30">
|
||||
<i class="icon-chevron-right"></i>
|
||||
Examples
|
||||
</a>
|
||||
<div id="example24" class="collapse">
|
||||
<div id="example30" class="collapse">
|
||||
|
||||
|
||||
<table class="manual-example">
|
||||
@@ -1674,11 +2093,11 @@ not</code>.</p>
|
||||
|
||||
<div>
|
||||
|
||||
<a data-toggle="collapse" href="#example25">
|
||||
<a data-toggle="collapse" href="#example31">
|
||||
<i class="icon-chevron-right"></i>
|
||||
Example
|
||||
</a>
|
||||
<div id="example25" class="collapse">
|
||||
<div id="example31" class="collapse">
|
||||
|
||||
|
||||
<table class="manual-example">
|
||||
@@ -1725,15 +2144,15 @@ not</code>.</p>
|
||||
|
||||
<div>
|
||||
|
||||
<a data-toggle="collapse" href="#example26">
|
||||
<a data-toggle="collapse" href="#example32">
|
||||
<i class="icon-chevron-right"></i>
|
||||
Examples
|
||||
</a>
|
||||
<div id="example26" class="collapse">
|
||||
<div id="example32" class="collapse">
|
||||
|
||||
|
||||
<table class="manual-example">
|
||||
<tr><th></th><td class="jqprogram">jq 'def addvalue(f): map(. + [$value]); addvalue(.[0])'</td></tr>
|
||||
<tr><th></th><td class="jqprogram">jq 'def addvalue(f): . + [f]; map(addvalue(.[0]))'</td></tr>
|
||||
<tr><th>Input</th><td>[[1,2],[10,20]]</td></tr>
|
||||
|
||||
|
||||
@@ -1748,7 +2167,7 @@ not</code>.</p>
|
||||
</table>
|
||||
|
||||
<table class="manual-example">
|
||||
<tr><th></th><td class="jqprogram">jq 'def addvalue(f): f as $x | map (. + $x); addvalue(.[0])'</td></tr>
|
||||
<tr><th></th><td class="jqprogram">jq 'def addvalue(f): f as $x | map(. + $x); addvalue(.[0])'</td></tr>
|
||||
<tr><th>Input</th><td>[[1,2],[10,20]]</td></tr>
|
||||
|
||||
|
||||
@@ -1756,7 +2175,7 @@ not</code>.</p>
|
||||
|
||||
<th>Output</th>
|
||||
|
||||
<td>[[1,2,[1,2]], [10,20,[1,2]]]</td>
|
||||
<td>[[1,2,1,2], [10,20,1,2]]</td>
|
||||
</tr>
|
||||
|
||||
|
||||
@@ -1819,11 +2238,11 @@ not</code>.</p>
|
||||
|
||||
<div>
|
||||
|
||||
<a data-toggle="collapse" href="#example27">
|
||||
<a data-toggle="collapse" href="#example33">
|
||||
<i class="icon-chevron-right"></i>
|
||||
Example
|
||||
</a>
|
||||
<div id="example27" class="collapse">
|
||||
<div id="example33" class="collapse">
|
||||
|
||||
|
||||
<table class="manual-example">
|
||||
@@ -1869,7 +2288,8 @@ not</code>.</p>
|
||||
|
||||
<p>The paths provided by this operation point to each of the posts that “stedolan” wrote, and we can comment on each of them in the same way that we did before:</p>
|
||||
|
||||
<pre><code>(.posts[] | select(.author == "stedolan") | .comments) |= . + ["terrible."]</code></pre>
|
||||
<pre><code>(.posts[] | select(.author == "stedolan") | .comments) |=
|
||||
. + ["terrible."]</code></pre>
|
||||
|
||||
|
||||
</section>
|
||||
|
||||
Reference in new issue
Block a user