From 6fc18d14f45ad4606378d974026b61721424a2d1 Mon Sep 17 00:00:00 2001
From: Nicolas Williams You can build it using the usual If you’re interested in using the latest development version, try: If you’re interested in using the lastest development version, try:./configure && make && sudo
make install
rigmarole.
diff --git a/manual/index.html b/manual/index.html
index dfdbcb9..9ec0b06 100644
--- a/manual/index.html
+++ b/manual/index.html
@@ -119,7 +119,7 @@
"Subtraction - `-`" : "Subtraction",
- "Multiplication, division - `*` and `/`" : "Multiplicationdivisionand",
+ "Multiplication, division, modulo - `*`, `/`, and `%`" : "Multiplicationdivisionmoduloand",
"`length`" : "length",
@@ -139,6 +139,10 @@
"`range`" : "range",
+ "`floor`" : "floor",
+
+ "`sqrt`" : "sqrt",
+
"`tonumber`" : "tonumber",
"`tostring`" : "tostring",
@@ -157,10 +161,26 @@
"`contains`" : "contains",
+ "`startswith`" : "startswith",
+
+ "`endswith`" : "endswith",
+
+ "`ltrimstr`" : "ltrimstr",
+
+ "`rtrimstr`" : "rtrimstr",
+
+ "`explode`" : "explode",
+
+ "`implode`" : "implode",
+
+ "`split`" : "split",
+
"`recurse`" : "recurse",
"String interpolation - `\\(foo)`" : "Stringinterpolationfoo",
+ "Convert to/from JSON" : "ConverttofromJSON",
+
"Format strings and escaping" : "Formatstringsandescaping",
"Builtin operators and functions" : "Builtinoperatorsandfunctions"
@@ -195,7 +215,7 @@
"`|=`" : "",
- "`+=`, `-=`, `*=`, `/=`, `//=`" : "",
+ "`+=`, `-=`, `*=`, `/=`, `%=`, `//=`" : "",
"Complex assignments" : "Complexassignments",
@@ -254,6 +274,12 @@ simpler:git clone https://github.com/stedolan/jq.git
cd jq
-autoreconf
+autoreconf -i
./configure
make
sudo make install
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.
+--online-input
/-I
:
When the top-level input value is an array produce its elements instead of the array. This allows on-line processing of potentially very large top-level arrays’ elements.
+--raw-input
/-R
:
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.
--unbuffered
Flush the output after each JSON object is printed (useful if you’re piping a slow data source into jq and piping jq’s output elsewhere).
+--sort-keys
/ -S
:
Output the fields of each object with the keys in sorted order.
+--raw-output
/ -r
:
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.
-f filename
/ --from-file filename
:
Read filter from the file rather than from a command line, like awk’s -f option. You can also use ’#’ to make comments.
+-e
/ --exit-status
:
Sets the exit status of jq to 10 if the last output values was false
, 11 if the last output value was null
, or 0 if the last output value was valid. Normally jq exits with 0, or 1 if there was any usage problem or other error.
--arg name value
:
This option passes a value to the jq program as a predefined variable. If you run jq with --arg foo bar
, then $foo
is available in the program and has the value "bar"
.
--argfile name filename
:
This option passes the first value from the named file as a value to the jq program as a predefined variable. If you run jq with --argfile foo bar
, then $foo
is available in the program and has the value resulting from parsing the content of the file named bar
.
.foo
The simplest useful filter is .foo. When given a JSON object (aka dictionary or hash) as input, it produces the value at the key “foo”, or null if there’s none present.
+The simplest useful filter is .foo
. When given a JSON object (aka dictionary or hash) as input, it produces the value at the key “foo”, or null if there’s none present.
If the key contains special characters, you need to surround it with double quotes like this: ."foo$"
.
jq '."foo"' | |
Input | {"foo": 42} |
Output | + +42 | +
You can also look up fields of an object using syntax like .["foo"]
(.foo 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 .[2]
returns the third element of the array.
The .[10:15]
syntax can be used to return a subarray of an array. The array returned by .[10:15]
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).
The .[10:15]
syntax can be used to return a subarray of an array or substring of a string. The array returned by .[10:15]
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).
jq '.[2:4]' | |
Input | "abcdefghi" |
Output | + +"cd" | +
jq '. / ", "' | |
Input | "a, b,c,d, e" |
Output | + +["a","b,c,d","e"] | +
floor
The floor
function returns the floor of its numeric input.
jq 'floor' | |
Input | 3.14159 |
Output | + +3 | +
sqrt
The sqrt
function returns the square root of its numeric input.
jq 'sqrt' | |
Input | 9 |
Output | + +3 | +
tonumber
jq '[.[]|startswith("foo")]' | |
Input | ["fo", "foo", "barfoo", "foobar", "barfoob"] |
Output | + +[false, true, false, true, false] | +
endswith
Outputs true
if . ends with the given string argument.
jq '[.[]|endswith("foo")]' | |
Input | ["foobar", "barfoo"] |
Output | + +[false, true, true, false, false] | +
ltrimstr
Outputs its input with the given prefix string removed, if it starts with it.
+ + +jq '[.[]|ltrimstr("foo")]' | |
Input | ["fo", "foo", "barfoo", "foobar", "afoo"] |
Output | + +["fo","","barfoo","bar","afoo"] | +
rtrimstr
Outputs its input with the given suffix string removed, if it starts with it.
+ + +jq '[.[]|rtrimstr("foo")]' | |
Input | ["fo", "foo", "barfoo", "foobar", "foob"] |
Output | + +["fo","","bar","foobar","foob"] | +
explode
Converts an input string into an array of the string’s codepoint numbers.
+ + +jq 'explode' | |
Input | "foobar" |
Output | + +[102,111,111,98,97,114] | +
implode
The inverse of explode.
+ + +jq 'implode' | |
Input | [65, 66, 67] |
Output | + +"ABC" | +
split
Splits an input string on the separator argument.
+ + +jq 'split(", ")' | |
Input | "a, b,c,d, e" |
Output | + +["a","b,c,d","e"] | +
recurse
jq '[.[]|tostring]' | |
Input | [1, "foo", ["foo"]] |
Output | + +["1","foo","[\"foo\"]"] | +
jq '[.[]|tojson]' | |
Input | [1, "foo", ["foo"]] |
Output | + +["1","\"foo\"","[\"foo\"]"] | +
jq '[.[]|tojson|fromjson]' | |
Input | [1, "foo", ["foo"]] |
Output | + +[1,"foo",["foo"]] | +
Format strings and escaping
@@ -2226,11 +2733,11 @@ map(foo) | from_entries, useful for doing some operation to all keys and