diff --git a/download/index.html b/download/index.html index 88412712..df05e19d 100644 --- a/download/index.html +++ b/download/index.html @@ -96,7 +96,7 @@
You can build it using the usual jq is a lightweight and flexible command-line JSON processor. jq is a lightweight and flexible command-line JSON processor. You can affect how jq reads and writes its input and output using some command-line options: Output the jq version and exit with zero. Sets the exit status of jq to 10 if the last output values was Sets the exit status of jq to 0 if the last output values was neither The simplest useful filter is If the key contains special characters, you need to surround it with double quotes like this: A filter of the form You can also look up fields of an object using syntax like The Just like You can also look up fields of an object using syntax like The The If you use the If you use the You can also use this on an object, and it will return all the values of the object. Like Objects are added by merging, that is, inserting all the key-value pairs from both objects into a single combined object. If both objects contain a value for the same key, the object on the right of the Objects are added by merging, that is, inserting all the key-value pairs from both objects into a single combined object. If both objects contain a value for the same key, the object on the right of the Dividing a string by another splits the first using the second as separators. Multiplying two objects will merge them recursively: this works like addition but if both objects contain a value for the same key, and the values are objects, the two are merged with the same strategy. The builtin function These built-ins select only inputs that are arrays, objects, iterables (arrays or objects), booleans, numbers, strings, null, non-null values, and non-iterables, respectively. Outputs the paths to all the elements in its input (except it does not output the empty list, representing . itself). Outputs the paths to all the leaves (non-array, non-object elements) in its input. The filter If the input is an empty array, The filter If the input is an empty array, The Outputs an array containing the indices in Outputs the index of the first ( Joins the array of elements given as input, using the argument as separator. It is the inverse of A quieter version of Short-hand for String interpolation - will produce the following output for the input will produce the following output for the input Note that the slashes, question mark, etc. in the URL are not escaped, as they were part of the string literal. Twitter has a JSON API, so let’s play with that. This URL gets us the last 5 tweets about JSON: GitHub has a JSON API, so let’s play with that. This URL gets us the last 5 commits from the jq repo: There’s lots of info and no whitespace, so to make it a bit more legible we pipe it through jq, telling jq to just spit the input back at us using the expression Github returns a ton of info here, and it’s relatively hard to read as it is. To syntax highlight it and order the attributes we pipe it through jq, telling jq to just spit the input back at us using the expression Let’s pull out the first tweet: There’s still far too much info for our purposes, so we can try just grab the first commit: The The Now let’s get the rest of the tweets: Now let’s get the rest of the commits: Data in jq is represented as streams of JSON values - every jq expression runs for each value in its input stream, and can produce any number of values to its output stream. Next, let’s try getting the URLs out of those API results as well. In each tweet, the Twitter API includes a field called “entities” which looks like this: Next, let’s try getting the URLs of the parrent commits out of the API results as well. In each commit, the GitHub API includes information about “parent” commits. There can be one or many. We want to pull out all of the “url” fields inside that array of url objects, and make a simple list of strings to go along with the “from_user” and “text” fields we already have. We want to pull out all of the “html_url” fields inside that array of parent commits and make a simple list of strings to go along with the “message” and “author” fields we already have. Here we’re making an object as before, but this time the urls field is being set to Here we’re making an object as before, but this time the ./configure && make && sudo
diff --git a/download/linux32/jq b/download/linux32/jq
index f9c29e7d..92041dbf 100755
Binary files a/download/linux32/jq and b/download/linux32/jq differ
diff --git a/download/linux64/jq b/download/linux64/jq
index 96241f76..78c9463f 100755
Binary files a/download/linux64/jq and b/download/linux64/jq differ
diff --git a/download/osx32/jq b/download/osx32/jq
index 5c596a75..61b1c7bd 100755
Binary files a/download/osx32/jq and b/download/osx32/jq differ
diff --git a/download/osx64/jq b/download/osx64/jq
index 18bbbb7c..f25aff86 100755
Binary files a/download/osx64/jq and b/download/osx64/jq differ
diff --git a/download/win32/jq.exe b/download/win32/jq.exe
index 83d406e0..3cae551f 100755
Binary files a/download/win32/jq.exe and b/download/win32/jq.exe differ
diff --git a/download/win64/jq.exe b/download/win64/jq.exe
index 458e5b30..88fb1186 100755
Binary files a/download/win64/jq.exe and b/download/win64/jq.exe differ
diff --git a/index.html b/index.html
index 0d01fcb7..7e478735 100644
--- a/index.html
+++ b/index.html
@@ -55,7 +55,7 @@
diff --git a/index/index.html b/index/index.html
index 0d01fcb7..7e478735 100644
--- a/index/index.html
+++ b/index/index.html
@@ -55,7 +55,7 @@
diff --git a/manual/index.html b/manual/index.html
index 4732c592..d9595685 100644
--- a/manual/index.html
+++ b/manual/index.html
@@ -93,12 +93,16 @@
"`.`" : "",
- "`.foo`" : "foo",
+ "`.foo`, `.foo.bar`" : "foofoobar",
- "`.[foo]`, `.[2]`, `.[10:15]`" : "foo21015",
+ "`.foo?`" : "foo",
+
+ "`.[
+
--version:--slurp/-s:-e / --exit-status: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.false nor null, 1 if the last output value was either false or null, or 4 if no valid result was ever produced. Normally jq exits with 2 if there was any usage problem or system error, 3 if there was a jq program compile error, or 0 if the jq program ran.
-
.foo.foo, .foo.bar.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.."foo$"..foo.bar is equivalent to .foo|.bar.
-
+ jq '."foo"' jq '.["foo"]'
@@ -467,14 +503,12 @@ simpler:
- Input {"foo": 42}
-
.[foo], .[2], .[10:15].foo?.["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..[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)..foo, but does not output even an error when . is not an array or an object.
+
+
+
+ jq '.foo?'
+
+
+ Input {"foo": 42, "bar": "less interesting data"}
+
+
+
+
+ Output
+
+ 42
+
+
+
+
+ jq '.foo?'
+
+
+ Input {"notfoo": true, "alsonotfoo": false}
+
+
+
+
+ Output
+
+ null
+
+
+
+
+ jq '.["foo"]?'
+
+
+ Input {"foo": 42}
+
+
+
+
+ Output
+
+ 42
+
+
+
+
+ jq '[.foo?]'
+
+
+ Input [1,2]
+
+
+
+
+ Output
+
+ []
+
+
.[<string>], .[2], .[10:15].["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..[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).? “operator” can also be used with the slice operator, as in .[10:15]?, which outputs values where the inputs are slice-able.
jq '.[0]'
@@ -586,18 +706,18 @@ simpler:
Input [{"name":"JSON", "good":true}, {"name":"XML", "good":false}] .[].[foo] syntax, but omit the index entirely, it will return all of the elements of an array. Running .[] with the input [1,2,3] will produce the numbers as three separate results, rather than as a single array..[index] syntax, but omit the index entirely, it will return all of the elements of an array. Running .[] with the input [1,2,3] will produce the numbers as three separate results, rather than as a single array.
@@ -662,6 +782,16 @@ simpler:
+
+
.[]?.[], but no errors will be output if . is not an array or object.
,
@@ -769,11 +899,11 @@ simpler:
@@ -825,11 +955,11 @@ simpler:
@@ -893,11 +1023,11 @@ simpler:
@@ -969,7 +1099,7 @@ simpler:
+ wins.+ wins. (For recursive merge use the * operator.)
@@ -1075,11 +1205,11 @@ simpler:
@@ -1128,14 +1258,16 @@ simpler:
@@ -1168,6 +1300,21 @@ simpler:
+
+
+
+ jq '{"k": {"a": 1, "b": 2}} * {"k": {"a": 0,"c": 3}}'
+
+
+ Input null
+
+
+
+
+ Output
+
+ {"k": {"a": 0, "b": 2, "c": 3}}
+
@@ -1263,11 +1410,11 @@ simpler:
@@ -1317,11 +1464,11 @@ simpler:
@@ -1359,6 +1506,58 @@ simpler:
+
+
deldel removes a key and its corresponding value from an object.
+
+
+
+ jq 'del(.foo)'
+
+
+ Input [{"foo": 42, "bar": 9001, "baz": 42}]
+
+
+
+
+ Output
+
+ {"bar": 9001, "baz": 42}
+
+
+
+
+ jq 'del(.[1, 2])'
+
+
+ Input [["foo", "bar", "baz"]]
+
+
+
+
+ Output
+
+ ["foo"]
+
to_entries, from_entries, with_entries
@@ -1441,11 +1640,11 @@ map(foo) | from_entries, useful for doing some operation to all keys and
@@ -1468,6 +1667,43 @@ map(foo) | from_entries, useful for doing some operation to all keys and
+
+
arrays, objects, iterables, booleans, numbers, strings, nulls, values, scalars
+
+
+
+ jq '.[]|numbers'
+
+
+ Input [[],{},1,"foo",null,true,false]
+
+
+
+
+ Output
+
+ 1
+
empty
@@ -1541,11 +1777,11 @@ map(foo) | from_entries, useful for doing some operation to all keys and
@@ -1568,6 +1804,84 @@ map(foo) | from_entries, useful for doing some operation to all keys and
+
+
pathspaths is equivalent to
+
+
+ def paths: path(recurse(if (type|. == "array" or . == "object") then .[] else empty end))|select(length > 0);
+
+
+
+ jq '[paths]'
+
+
+ Input [1,[[],{"a":2}]]
+
+
+
+
+ Output
+
+ [[0],[1],[1,0],[1,1],[1,1,"a"]]
+
+
leaf_paths
+
+
+
+ jq '[leaf_paths]'
+
+
+ Input [1,[[],{"a":2}]]
+
+
+
+
+ Output
+
+ [[0],[1,1,"a"]]
+
add
@@ -1637,6 +1951,144 @@ map(foo) | from_entries, useful for doing some operation to all keys and
+
+
anyany takes as input an array of boolean values, and produces true as output if any of the the elements of the array is true.any returns false.
+
+
+
+ jq 'any'
+
+
+ Input [true, false]
+
+
+
+
+ Output
+
+ true
+
+
+
+
+ jq 'any'
+
+
+ Input [false, false]
+
+
+
+
+ Output
+
+ false
+
+
+
+
+ jq 'any'
+
+
+ Input []
+
+
+
+
+ Output
+
+ false
+
+
allall takes as input an array of boolean values, and produces true as output if all of the the elements of the array are true.all returns true.
+
+
+
+ jq 'all'
+
+
+ Input [true, false]
+
+
+
+
+ Output
+
+ false
+
+
+
+
+ jq 'all'
+
+
+ Input [true, true]
+
+
+
+
+ Output
+
+ true
+
+
+
+
+ jq 'all'
+
+
+ Input []
+
+
+
+
+ Output
+
+ true
+
range
@@ -1706,11 +2158,11 @@ map(foo) | from_entries, useful for doing some operation to all keys and
@@ -1743,11 +2195,11 @@ map(foo) | from_entries, useful for doing some operation to all keys and
@@ -1780,11 +2232,11 @@ map(foo) | from_entries, useful for doing some operation to all keys and
@@ -1824,11 +2276,11 @@ map(foo) | from_entries, useful for doing some operation to all keys and
@@ -1875,11 +2327,11 @@ map(foo) | from_entries, useful for doing some operation to all keys and
@@ -1932,11 +2384,11 @@ map(foo) | from_entries, useful for doing some operation to all keys and
@@ -1986,11 +2438,11 @@ map(foo) | from_entries, useful for doing some operation to all keys and
@@ -2023,11 +2475,11 @@ map(foo) | from_entries, useful for doing some operation to all keys and
@@ -2075,11 +2527,11 @@ map(foo) | from_entries, useful for doing some operation to all keys and
@@ -2102,6 +2554,58 @@ map(foo) | from_entries, useful for doing some operation to all keys and
+
+
unique_byunique_by(.foo) function takes as input an array and produces an array of the same elements, in sorted order, with elqements with a duplicate .foo field removed. Think of it as making an array by taking one element out of every group produced by group_by.
+
+
+
+ jq 'unique_by(.foo)'
+
+
+ Input [{"foo": 1, "bar": 2}, {"foo": 1, "bar": 3}, {"foo": 4, "bar": 5}]
+
+
+
+
+ Output
+
+ [{"foo": 1, "bar": 2}, {"foo": 4, "bar": 5}]
+
+
+
+
+ jq 'unique_by(length)'
+
+
+ Input ["chunky", "bacon", "kitten", "cicada", "asparagus"]
+
+
+
+
+ Output
+
+ ["chunky", "bacon", "asparagus"]
+
reverse
@@ -2149,11 +2653,11 @@ map(foo) | from_entries, useful for doing some operation to all keys and
@@ -2236,6 +2740,125 @@ map(foo) | from_entries, useful for doing some operation to all keys and
+
+
indices(s). where s occurs. The input may be an array, in which case if s is an array then the indices output will be those where all elements in . match those of s.
+
+
+
+ jq 'indices(", ")'
+
+
+ Input "a,b, cd, efg, hijk"
+
+
+
+
+ Output
+
+ [3,7,12]
+
+
+
+
+ jq 'indices(1)'
+
+
+ Input [0,1,2,1,3,1,4]
+
+
+
+
+ Output
+
+ [1,3,5]
+
+
+
+
+ jq 'indices([1,2])'
+
+
+ Input [0,1,2,3,1,4,2,5,1,2,6,7]
+
+
+
+
+ Output
+
+ [1,8]
+
+
index(s), rindex(s)index) or last (rindex) occurrence of s in the input.
+
+
+
+ jq 'index(", ")'
+
+
+ Input "a,b, cd, efg, hijk"
+
+
+
+
+ Output
+
+ 3
+
+
+
+
+ jq 'rindex(", ")]'
+
+
+ Input "a,b, cd, efg, hijk"
+
+
+
+
+ Output
+
+ 12
+
startswith
@@ -2283,11 +2906,11 @@ map(foo) | from_entries, useful for doing some operation to all keys and
@@ -2320,11 +2943,11 @@ map(foo) | from_entries, useful for doing some operation to all keys and
@@ -2357,11 +2980,11 @@ map(foo) | from_entries, useful for doing some operation to all keys and
@@ -2394,11 +3017,11 @@ map(foo) | from_entries, useful for doing some operation to all keys and
@@ -2431,11 +3054,11 @@ map(foo) | from_entries, useful for doing some operation to all keys and
@@ -2468,11 +3091,11 @@ map(foo) | from_entries, useful for doing some operation to all keys and
@@ -2495,6 +3118,43 @@ map(foo) | from_entries, useful for doing some operation to all keys and
+
+
joinsplit: that is, running split("foo") | join("foo") over any input string returns said input string.
+
+
+
+ jq 'join(", ")'
+
+
+ Input ["a","b,c,d","e"]
+
+
+
+
+ Output
+
+ "a, b,c,d, e"
+
recurse
@@ -2565,6 +3225,55 @@ map(foo) | from_entries, useful for doing some operation to all keys and
+
+
recurse_downrecurse(.[]), equivalent to:
+
+
+ def recurse_down: recurse(.[]?);
+
..recurse_down. This is intended to resemble the XPath // operator. Note that ..a does not work; use ..|a instead.
+
+
+
+ jq '..|.a?'
+
+
+ Input [[{"a":1}]]
+
+
+
+
+ Output
+
+ 1
+
\(foo)
@@ -2612,11 +3321,11 @@ map(foo) | from_entries, useful for doing some operation to all keys and
@@ -2724,20 +3433,20 @@ map(foo) | from_entries, useful for doing some operation to all keys and
-@uri "http://www.google.com/search?q=\(.search)"{"search":"jq!"}:{"search":"what is jq?"}:
+http://www.google.com/search?q=jq%21"http://www.google.com/search?q=what%20is%20jq%3f"
@@ -2793,11 +3502,11 @@ map(foo) | from_entries, useful for doing some operation to all keys and
@@ -2858,11 +3567,11 @@ B end instead.
@@ -2903,11 +3612,11 @@ end'
@@ -2947,11 +3656,11 @@ not.
@@ -3059,11 +3768,11 @@ not.
@@ -3159,11 +3868,11 @@ not.
@@ -3210,11 +3919,11 @@ not.
@@ -3270,11 +3979,11 @@ not.
@@ -3349,11 +4058,11 @@ not.
diff --git a/sitemap.xml b/sitemap.xml
index 4d79f24f..37d6c75d 100644
--- a/sitemap.xml
+++ b/sitemap.xml
@@ -2,22 +2,22 @@
Tutorial
- curl 'http://search.twitter.com/search.json?q=json&rpp=5&include_entities=true'
+ curl 'https://api.github.com/repos/stedolan/jq/commits?per_page=5'
Show result
{"completed_in":0.108,"max_id":247677287108067328,"max_id_str":"247677287108067328","next_page":"?page=2&max_id=247677287108067328&q=json&rpp=5&include_entities=1","page":1,"query":"json","refresh_url":"?since_id=247677287108067328&q=json&include_entities=1","results":[{"created_at":"Mon, 17 Sep 2012 12:44:01 +0000","entities":{"hashtags":[],"urls":[{"url":"http:\/\/t.co\/XRvh1ZVw","expanded_url":"http:\/\/jase.im\/Ri7I0M","display_url":"jase.im\/Ri7I0M","indices":[112,132]}],"user_mentions":[{"screen_name":"imagemechanics","name":"Jason Cotterell","id":57271393,"id_str":"57271393","indices":[3,18]}]},"from_user":"_AaronNg","from_user_id":79771704,"from_user_id_str":"79771704","from_user_name":"NgChenChong","geo":null,"id":247677287108067328,"id_str":"247677287108067328","iso_language_code":"en","metadata":{"result_type":"recent"},"profile_image_url":"http:\/\/a0.twimg.com\/profile_images\/2523558403\/ek8mo4j4beq84iw28gjl_normal.jpeg","profile_image_url_https":"https:\/\/si0.twimg.com\/profile_images\/2523558403\/ek8mo4j4beq84iw28gjl_normal.jpeg","source":"<a href="http:\/\/twitter.com\/">web<\/a>","text":"RT @imagemechanics: iPhone 5 website teardown: How Apple compresses video using JPEG, JSON, and <canvas>.\nhttp:\/\/t.co\/XRvh1ZVw","to_user":null,"to_user_id":0,"to_user_id_str":"0","to_user_name":null}, ...
+ [
+ {
+ "sha": "d25341478381063d1c76e81b3a52e0592a7c997f",
+ "commit": {
+ "author": {
+ "name": "Stephen Dolan",
+ "email": "mu@netsoc.tcd.ie",
+ "date": "2013-06-22T16:30:59Z"
+ },
+ "committer": {
+ "name": "Stephen Dolan",
+ "email": "mu@netsoc.tcd.ie",
+ "date": "2013-06-22T16:30:59Z"
+ },
+ "message": "Merge pull request #162 from stedolan/utf8-fixes\n\nUtf8 fixes. Closes #161",
+ "tree": {
+ "sha": "6ab697a8dfb5a96e124666bf6d6213822599fb40",
+ "url": "https://api.github.com/repos/stedolan/jq/git/trees/6ab697a8dfb5a96e124666bf6d6213822599fb40"
+ },
+ "url": "https://api.github.com/repos/stedolan/jq/git/commits/d25341478381063d1c76e81b3a52e0592a7c997f",
+ "comment_count": 0
+ },
+ "url": "https://api.github.com/repos/stedolan/jq/commits/d25341478381063d1c76e81b3a52e0592a7c997f",
+ "html_url": "https://github.com/stedolan/jq/commit/d25341478381063d1c76e81b3a52e0592a7c997f",
+ "comments_url": "https://api.github.com/repos/stedolan/jq/commits/d25341478381063d1c76e81b3a52e0592a7c997f/comments",
+ "author": {
+ "login": "stedolan",
+ ...
.:.:curl 'http://search.twitter.com/search.json?q=json&rpp=5&include_entities=true' | jq '.'
+ curl 'https://api.github.com/repos/stedolan/jq/commits?per_page=5' | jq '.'
Show result
-{
- "since_id_str": "0",
- "since_id": 0,
- "results_per_page": 5,
- "completed_in": 0.108,
- "max_id": 247677287108067330,
- "max_id_str": "247677287108067328",
- "next_page": "?page=2&max_id=247677287108067328&q=json&rpp=5&include_entities=1",
- "page": 1,
- "query": "json",
- "refresh_url": "?since_id=247677287108067328&q=json&include_entities=1",
- "results": [
- {
- "from_user_name": "NgChenChong",
- "from_user_id_str": "79771704",
- "from_user_id": 79771704,
- "from_user": "_AaronNg",
- "iso_language_code": "en",
- "text": "RT @imagemechanics: iPhone 5 website teardown: How Apple compresses video using JPEG, JSON, and <canvas>.\nhttp://t.co/XRvh1ZVw",
- "to_user": null
- /* lots more fields... */
- },
- /* lots more results... */
- ]
-}
+ [
+ {
+ "parents": [
+ {
+ "html_url": "https://github.com/stedolan/jq/commit/54b9c9bdb225af5d886466d72f47eafc51acb4f7",
+ "url": "https://api.github.com/repos/stedolan/jq/commits/54b9c9bdb225af5d886466d72f47eafc51acb4f7",
+ "sha": "54b9c9bdb225af5d886466d72f47eafc51acb4f7"
+ },
+ {
+ "html_url": "https://github.com/stedolan/jq/commit/8b1b503609c161fea4b003a7179b3fbb2dd4345a",
+ "url": "https://api.github.com/repos/stedolan/jq/commits/8b1b503609c161fea4b003a7179b3fbb2dd4345a",
+ "sha": "8b1b503609c161fea4b003a7179b3fbb2dd4345a"
+ }
+ ],
+ "committer": {
+ "type": "User",
+ "received_events_url": "https://api.github.com/users/stedolan/received_events",
+ "events_url": "https://api.github.com/users/stedolan/events{/privacy}",
+ "repos_url": "https://api.github.com/users/stedolan/repos",
+ "organizations_url": "https://api.github.com/users/stedolan/orgs",
+...
curl 'http://search.twitter.com/search.json?q=json&rpp=5&include_entities=true' | jq '.results[0]'
+ curl 'https://api.github.com/repos/stedolan/jq/commits?per_page=5' | jq '.[0]'
Show result
{
- "from_user_name": "NgChenChong",
- "from_user_id_str": "79771704",
- "from_user_id": 79771704,
- "from_user": "_AaronNg",
- "iso_language_code": "en",
- "text": "RT @imagemechanics: iPhone 5 website teardown: How Apple compresses video using JPEG, JSON, and <canvas>.\nhttp://t.co/XRvh1ZVw",
- "to_user": null
- /* lots more fields... */
-},
+ "parents": [
+ {
+ "html_url": "https://github.com/stedolan/jq/commit/54b9c9bdb225af5d886466d72f47eafc51acb4f7",
+ "url": "https://api.github.com/repos/stedolan/jq/commits/54b9c9bdb225af5d886466d72f47eafc51acb4f7",
+ "sha": "54b9c9bdb225af5d886466d72f47eafc51acb4f7"
+ },
+ {
+ "html_url": "https://github.com/stedolan/jq/commit/8b1b503609c161fea4b003a7179b3fbb2dd4345a",
+ "url": "https://api.github.com/repos/stedolan/jq/commits/8b1b503609c161fea4b003a7179b3fbb2dd4345a",
+ "sha": "8b1b503609c161fea4b003a7179b3fbb2dd4345a"
+ }
+ ],
+ "committer": {
+ "type": "User",
+ "received_events_url": "https://api.github.com/users/stedolan/received_events",
+ "events_url": "https://api.github.com/users/stedolan/events{/privacy}",
+ "repos_url": "https://api.github.com/users/stedolan/repos",
+ "organizations_url": "https://api.github.com/users/stedolan/orgs",
+ "subscriptions_url": "https://api.github.com/users/stedolan/subscriptions",
+ "starred_url": "https://api.github.com/users/stedolan/starred{/owner}{/repo}",
+ "gists_url": "https://api.github.com/users/stedolan/gists{/gist_id}",
+ "login": "stedolan",
+ "id": 79765,
+ "avatar_url": "https://1.gravatar.com/avatar/31de909d8e55dd07ed782d92ece59842?d=https%3A%2F%2Fidenticons.github.com%2Ffc5b6765b1c9cfaecea48ae71df4d279.png",
+ "gravatar_id": "31de909d8e55dd07ed782d92ece59842",
+ "url": "https://api.github.com/users/stedolan",
+ "html_url": "https://github.com/stedolan",
+ "followers_url": "https://api.github.com/users/stedolan/followers",
+ "following_url": "https://api.github.com/users/stedolan/following{/other_user}"
+ },
+ "author": {
+ "type": "User",
+ "received_events_url": "https://api.github.com/users/stedolan/received_events",
+ "events_url": "https://api.github.com/users/stedolan/events{/privacy}",
+ "repos_url": "https://api.github.com/users/stedolan/repos",
+ "organizations_url": "https://api.github.com/users/stedolan/orgs",
+ "subscriptions_url": "https://api.github.com/users/stedolan/subscriptions",
+ "starred_url": "https://api.github.com/users/stedolan/starred{/owner}{/repo}",
+ "gists_url": "https://api.github.com/users/stedolan/gists{/gist_id}",
+ "login": "stedolan",
+ "id": 79765,
+ "avatar_url": "https://1.gravatar.com/avatar/31de909d8e55dd07ed782d92ece59842?d=https%3A%2F%2Fidenticons.github.com%2Ffc5b6765b1c9cfaecea48ae71df4d279.png",
+ "gravatar_id": "31de909d8e55dd07ed782d92ece59842",
+ "url": "https://api.github.com/users/stedolan",
+ "html_url": "https://github.com/stedolan",
+ "followers_url": "https://api.github.com/users/stedolan/followers",
+ "following_url": "https://api.github.com/users/stedolan/following{/other_user}"
+ },
+ "comments_url": "https://api.github.com/repos/stedolan/jq/commits/d25341478381063d1c76e81b3a52e0592a7c997f/comments",
+ "html_url": "https://github.com/stedolan/jq/commit/d25341478381063d1c76e81b3a52e0592a7c997f",
+ "url": "https://api.github.com/repos/stedolan/jq/commits/d25341478381063d1c76e81b3a52e0592a7c997f",
+ "commit": {
+ "comment_count": 0,
+ "url": "https://api.github.com/repos/stedolan/jq/git/commits/d25341478381063d1c76e81b3a52e0592a7c997f",
+ "tree": {
+ "url": "https://api.github.com/repos/stedolan/jq/git/trees/6ab697a8dfb5a96e124666bf6d6213822599fb40",
+ "sha": "6ab697a8dfb5a96e124666bf6d6213822599fb40"
+ },
+ "message": "Merge pull request #162 from stedolan/utf8-fixes\n\nUtf8 fixes. Closes #161",
+ "committer": {
+ "date": "2013-06-22T16:30:59Z",
+ "email": "mu@netsoc.tcd.ie",
+ "name": "Stephen Dolan"
+ },
+ "author": {
+ "date": "2013-06-22T16:30:59Z",
+ "email": "mu@netsoc.tcd.ie",
+ "name": "Stephen Dolan"
+ }
+ },
+ "sha": "d25341478381063d1c76e81b3a52e0592a7c997f"
+}
jq '.results[0] | {from_user, text}'
+ jq '.[0] | {message: .commit.message, name: .commit.committer.name}'
Show result
{
- "text": "RT @imagemechanics: iPhone 5 website teardown: How Apple compresses video using JPEG, JSON, and <canvas>.\nhttp://t.co/XRvh1ZVw",
- "from_user": "_AaronNg"
+ "name": "Stephen Dolan",
+ "message": "Merge pull request #162 from stedolan/utf8-fixes\n\nUtf8 fixes. Closes #161"
}
| operator in jq feeds the output of one filter (.results[0] which gets the first element of the results array) into the input of another ({from_user, text} which builds an object of those two fields).| operator in jq feeds the output of one filter (.[0] which gets the first element of the array in the response) into the input of another ({...} which builds an object out of those fields). You can access nested attributes, such as .commit.message:jq '.results[] | {from_user, text}'
+ jq '.[] | {message: .commit.message, name: .commit.committer.name}'
Show result
{
- "text": "RT @imagemechanics: iPhone 5 website teardown: How Apple compresses video using JPEG, JSON, and <canvas>.\nhttp://t.co/XRvh1ZVw",
- "from_user": "_AaronNg"
+ "name": "Stephen Dolan",
+ "message": "Merge pull request #162 from stedolan/utf8-fixes\n\nUtf8 fixes. Closes #161"
}
{
- "text": "RT @_kud: iPhone 5 website teardown: How Apple compresses video using JPEG, JSON, and <canvas> -- http://t.co/Lhp92IqD",
- "from_user": "blouerat"
+ "name": "Stephen Dolan",
+ "message": "Reject all overlong UTF8 sequences."
}
{
- "text": "Dynamic Forms Mobile App by pmadiset: Few Forms details are hosted on our server in the form of JSON. This JSON ... http://t.co/7KALdWaX",
- "from_user": "cebu_iphone"
+ "name": "Stephen Dolan",
+ "message": "Fix various UTF8 parsing bugs.\n\nIn particular, parse bad UTF8 by replacing the broken bits with U+FFFD\nand resychronise correctly after broken sequences."
}
{
- "text": "iPhone 5 website insanity - Video compressing using JPEG, JSON, and <canvas> http://t.co/28Jesbio (Oh #Apple, U So #Awesome...)",
- "from_user": "dieswaytoofast"
+ "name": "Stephen Dolan",
+ "message": "Fix example in manual for `floor`. See #155."
}
{
- "text": "RT @umutm: A very nice web-based JSON editor - http://t.co/M70snaIf",
- "from_user": "Leolik"
+ "name": "Nicolas Williams",
+ "message": "Document floor"
}
.results[] returns each element of the results array, one at a time, which are all fed into {from_user, text}..[] returns each element of the array returned in the response, one at a time, which are all fed into {message: .commit.message, name: .commit.committer.name}.jq '[.results[] | {from_user, text}]'
+ jq '[.[] | {message: .commit.message, name: .commit.committer.name}]'
Show result
[
{
- "text": "RT @imagemechanics: iPhone 5 website teardown: How Apple compresses video using JPEG, JSON, and <canvas>.\nhttp://t.co/XRvh1ZVw",
- "from_user": "_AaronNg"
+ "name": "Stephen Dolan",
+ "message": "Merge pull request #162 from stedolan/utf8-fixes\n\nUtf8 fixes. Closes #161"
},
{
- "text": "RT @_kud: iPhone 5 website teardown: How Apple compresses video using JPEG, JSON, and <canvas> -- http://t.co/Lhp92IqD",
- "from_user": "blouerat"
+ "name": "Stephen Dolan",
+ "message": "Reject all overlong UTF8 sequences."
},
{
- "text": "Dynamic Forms Mobile App by pmadiset: Few Forms details are hosted on our server in the form of JSON. This JSON ... http://t.co/7KALdWaX",
- "from_user": "cebu_iphone"
+ "name": "Stephen Dolan",
+ "message": "Fix various UTF8 parsing bugs.\n\nIn particular, parse bad UTF8 by replacing the broken bits with U+FFFD\nand resychronise correctly after broken sequences."
},
{
- "text": "iPhone 5 website insanity - Video compressing using JPEG, JSON, and <canvas> http://t.co/28Jesbio (Oh #Apple, U So #Awesome...)",
- "from_user": "dieswaytoofast"
+ "name": "Stephen Dolan",
+ "message": "Fix example in manual for `floor`. See #155."
},
{
- "text": "RT @umutm: A very nice web-based JSON editor - http://t.co/M70snaIf",
- "from_user": "Leolik"
+ "name": "Nicolas Williams",
+ "message": "Document floor"
}
]
-
+{
- "user_mentions": [],
- "urls": [{
- "indices": [83, 103],
- "display_url": "bit.ly/StniqT",
- "expanded_url": "http://bit.ly/StniqT",
- "url": "http://t.co/28Jesbio"
- }],
- "hashtags": [
- {"indices": [108, 114], "text": "Apple" },
- {"indices": [121, 129], "text": "Awesome"}
- ]
-}
-"parents": [
+ {
+ "html_url": "https://github.com/stedolan/jq/commit/54b9c9bdb225af5d886466d72f47eafc51acb4f7",
+ "url": "https://api.github.com/repos/stedolan/jq/commits/54b9c9bdb225af5d886466d72f47eafc51acb4f7",
+ "sha": "54b9c9bdb225af5d886466d72f47eafc51acb4f7"
+ },
+ {
+ "html_url": "https://github.com/stedolan/jq/commit/8b1b503609c161fea4b003a7179b3fbb2dd4345a",
+ "url": "https://api.github.com/repos/stedolan/jq/commits/8b1b503609c161fea4b003a7179b3fbb2dd4345a",
+ "sha": "8b1b503609c161fea4b003a7179b3fbb2dd4345a"
+ }
+]jq '.results[] | {from_user, text, urls: [.entities.urls[].url]}'
+ jq '[.[] | {message: .commit.message, name: .commit.committer.name, parents: [.parents[].html_url]}]'
Show result
{
- "urls": [
- "http://t.co/XRvh1ZVw"
- ],
- "text": "RT @imagemechanics: iPhone 5 website teardown: How Apple compresses video using JPEG, JSON, and <canvas>.\nhttp://t.co/XRvh1ZVw",
- "from_user": "_AaronNg"
-}
-{
- "urls": [
- "http://t.co/Lhp92IqD"
- ],
- "text": "RT @_kud: iPhone 5 website teardown: How Apple compresses video using JPEG, JSON, and <canvas> -- http://t.co/Lhp92IqD",
- "from_user": "blouerat"
-}
-{
- "urls": [
- "http://t.co/7KALdWaX"
- ],
- "text": "Dynamic Forms Mobile App by pmadiset: Few Forms details are hosted on our server in the form of JSON. This JSON ... http://t.co/7KALdWaX",
- "from_user": "cebu_iphone"
-}
-{
- "urls": [
- "http://t.co/28Jesbio"
- ],
- "text": "iPhone 5 website insanity - Video compressing using JPEG, JSON, and <canvas> http://t.co/28Jesbio (Oh #Apple, U So #Awesome...)",
- "from_user": "dieswaytoofast"
-}
-{
- "urls": [
- "http://t.co/M70snaIf"
- ],
- "text": "RT @umutm: A very nice web-based JSON editor - http://t.co/M70snaIf",
- "from_user": "Leolik"
-}
+ [
+ {
+ "parents": [
+ "https://github.com/stedolan/jq/commit/54b9c9bdb225af5d886466d72f47eafc51acb4f7",
+ "https://github.com/stedolan/jq/commit/8b1b503609c161fea4b003a7179b3fbb2dd4345a"
+ ],
+ "name": "Stephen Dolan",
+ "message": "Merge pull request #162 from stedolan/utf8-fixes\n\nUtf8 fixes. Closes #161"
+ },
+ {
+ "parents": [
+ "https://github.com/stedolan/jq/commit/ff48bd6ec538b01d1057be8e93b94eef6914e9ef"
+ ],
+ "name": "Stephen Dolan",
+ "message": "Reject all overlong UTF8 sequences."
+ },
+ {
+ "parents": [
+ "https://github.com/stedolan/jq/commit/54b9c9bdb225af5d886466d72f47eafc51acb4f7"
+ ],
+ "name": "Stephen Dolan",
+ "message": "Fix various UTF8 parsing bugs.\n\nIn particular, parse bad UTF8 by replacing the broken bits with U+FFFD\nand resychronise correctly after broken sequences."
+ },
+ {
+ "parents": [
+ "https://github.com/stedolan/jq/commit/3dcdc582ea993afea3f5503a78a77675967ecdfa"
+ ],
+ "name": "Stephen Dolan",
+ "message": "Fix example in manual for `floor`. See #155."
+ },
+ {
+ "parents": [
+ "https://github.com/stedolan/jq/commit/7c4171d414f647ab08bcd20c76a4d8ed68d9c602"
+ ],
+ "name": "Nicolas Williams",
+ "message": "Document floor"
+ }
+]
[.entities.urls[].url], which collects all of the URLs defined in the entities object.parents field is being set to [.parents[].html_url]}], which collects all of the parent commit urls defined in the parents object.