Skip to content
Myr

Update wording and json bodies in tutorial

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by David Tolnay · committed by David Tolnay · parent dea7868 · Browse files · 1 file+147 added−142 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

1 file+147 added−142 removed

  • other:+147 added−142 removed

1 file+147 added−142 removed

modified:docs/content/1.tutorial/default.yml+147 added-142 removed
1headline: Tutorial2body:3 - text: |45 GitHub has a JSON API, so let's play with that. This URL gets6 us the last 5 commits from the jq repo:5 GitHub has a JSON API, so let's play with that. This URL gets us the last6 5 commits from the jq repo.78 - command: "curl 'https://api.github.com/repos/stedolan/jq/commits?per_page=5'"9 result: |10 [
22 unmodified lines
33 "html_url": "https://github.com/stedolan/jq/commit/d25341478381063d1c76e81b3a52e0592a7c997f",34 "comments_url": "https://api.github.com/repos/stedolan/jq/commits/d25341478381063d1c76e81b3a52e0592a7c997f/comments",35 "author": {36 "login": "stedolan",37 ...37 ...3839 - text: |40 Github returns a ton of info here, and it's relatively hard to41 read as it is. To syntax highlight it and order the attributes we pipe42 it through jq, telling jq to just spit the input back at us using43 the expression `.`:4041 GitHub returns nicely formatted JSON. For servers that don't, it can be42 helpful to pipe the response through jq to pretty-print it. The simplest43 jq program is the expression `.`, which takes the input and produces it44 unchanged as output.4546 - command: "curl 'https://api.github.com/repos/stedolan/jq/commits?per_page=5' | jq '.'"47 result: |48 [49 {49 "parents": [50 {51 "html_url": "https://github.com/stedolan/jq/commit/54b9c9bdb225af5d886466d72f47eafc51acb4f7",52 "url": "https://api.github.com/repos/stedolan/jq/commits/54b9c9bdb225af5d886466d72f47eafc51acb4f7",53 "sha": "54b9c9bdb225af5d886466d72f47eafc51acb4f7"50 "sha": "d25341478381063d1c76e81b3a52e0592a7c997f",51 "commit": {52 "author": {53 "name": "Stephen Dolan",54 "email": "mu@netsoc.tcd.ie",55 "date": "2013-06-22T16:30:59Z"56 },55 {56 "html_url": "https://github.com/stedolan/jq/commit/8b1b503609c161fea4b003a7179b3fbb2dd4345a",57 "url": "https://api.github.com/repos/stedolan/jq/commits/8b1b503609c161fea4b003a7179b3fbb2dd4345a",58 "sha": "8b1b503609c161fea4b003a7179b3fbb2dd4345a"59 }60 ],61 "committer": {62 "type": "User",63 "received_events_url": "https://api.github.com/users/stedolan/received_events",64 "events_url": "https://api.github.com/users/stedolan/events{/privacy}",65 "repos_url": "https://api.github.com/users/stedolan/repos",66 "organizations_url": "https://api.github.com/users/stedolan/orgs",57 "committer": {58 "name": "Stephen Dolan",59 "email": "mu@netsoc.tcd.ie",60 "date": "2013-06-22T16:30:59Z"61 },62 "message": "Merge pull request #162 from stedolan/utf8-fixes\n\nUtf8 fixes. Closes #161",63 "tree": {64 "sha": "6ab697a8dfb5a96e124666bf6d6213822599fb40",65 "url": "https://api.github.com/repos/stedolan/jq/git/trees/6ab697a8dfb5a96e124666bf6d6213822599fb40"66 },67 "url": "https://api.github.com/repos/stedolan/jq/git/commits/d25341478381063d1c76e81b3a52e0592a7c997f",68 "comment_count": 069 },70 "url": "https://api.github.com/repos/stedolan/jq/commits/d25341478381063d1c76e81b3a52e0592a7c997f",71 "html_url": "https://github.com/stedolan/jq/commit/d25341478381063d1c76e81b3a52e0592a7c997f",72 "comments_url": "https://api.github.com/repos/stedolan/jq/commits/d25341478381063d1c76e81b3a52e0592a7c997f/comments",73 "author": {74 "login": "stedolan",75 ...7677 - text: |7871 There's still far too much info for our purposes, so we can try72 just grab the first commit:79 We can use jq to extract just the first commit.807481 - command: "curl 'https://api.github.com/repos/stedolan/jq/commits?per_page=5' | jq '.[0]'"82 result: |83 {78 "parents": [79 {80 "html_url": "https://github.com/stedolan/jq/commit/54b9c9bdb225af5d886466d72f47eafc51acb4f7",81 "url": "https://api.github.com/repos/stedolan/jq/commits/54b9c9bdb225af5d886466d72f47eafc51acb4f7",82 "sha": "54b9c9bdb225af5d886466d72f47eafc51acb4f7"84 "sha": "d25341478381063d1c76e81b3a52e0592a7c997f",85 "commit": {86 "author": {87 "name": "Stephen Dolan",88 "email": "mu@netsoc.tcd.ie",89 "date": "2013-06-22T16:30:59Z"90 },84 {85 "html_url": "https://github.com/stedolan/jq/commit/8b1b503609c161fea4b003a7179b3fbb2dd4345a",86 "url": "https://api.github.com/repos/stedolan/jq/commits/8b1b503609c161fea4b003a7179b3fbb2dd4345a",87 "sha": "8b1b503609c161fea4b003a7179b3fbb2dd4345a"88 }89 ],90 "committer": {91 "type": "User",92 "received_events_url": "https://api.github.com/users/stedolan/received_events",93 "events_url": "https://api.github.com/users/stedolan/events{/privacy}",94 "repos_url": "https://api.github.com/users/stedolan/repos",95 "organizations_url": "https://api.github.com/users/stedolan/orgs",96 "subscriptions_url": "https://api.github.com/users/stedolan/subscriptions",97 "starred_url": "https://api.github.com/users/stedolan/starred{/owner}{/repo}",98 "gists_url": "https://api.github.com/users/stedolan/gists{/gist_id}",91 "committer": {92 "name": "Stephen Dolan",93 "email": "mu@netsoc.tcd.ie",94 "date": "2013-06-22T16:30:59Z"95 },96 "message": "Merge pull request #162 from stedolan/utf8-fixes\n\nUtf8 fixes. Closes #161",97 "tree": {98 "sha": "6ab697a8dfb5a96e124666bf6d6213822599fb40",99 "url": "https://api.github.com/repos/stedolan/jq/git/trees/6ab697a8dfb5a96e124666bf6d6213822599fb40"100 },101 "url": "https://api.github.com/repos/stedolan/jq/git/commits/d25341478381063d1c76e81b3a52e0592a7c997f",102 "comment_count": 0103 },104 "url": "https://api.github.com/repos/stedolan/jq/commits/d25341478381063d1c76e81b3a52e0592a7c997f",105 "html_url": "https://github.com/stedolan/jq/commit/d25341478381063d1c76e81b3a52e0592a7c997f",106 "comments_url": "https://api.github.com/repos/stedolan/jq/commits/d25341478381063d1c76e81b3a52e0592a7c997f/comments",107 "author": {108 "login": "stedolan",109 "id": 79765,101 "avatar_url": "https://1.gravatar.com/avatar/31de909d8e55dd07ed782d92ece59842?d=https%3A%2F%2Fidenticons.github.com%2Ffc5b6765b1c9cfaecea48ae71df4d279.png",102 "gravatar_id": "31de909d8e55dd07ed782d92ece59842",110 "avatar_url": "https://avatars.githubusercontent.com/u/79765?v=3",111 "gravatar_id": "",112 "url": "https://api.github.com/users/stedolan",113 "html_url": "https://github.com/stedolan",114 "followers_url": "https://api.github.com/users/stedolan/followers",106 "following_url": "https://api.github.com/users/stedolan/following{/other_user}"107 },108 "author": {109 "type": "User",110 "received_events_url": "https://api.github.com/users/stedolan/received_events",111 "events_url": "https://api.github.com/users/stedolan/events{/privacy}",112 "repos_url": "https://api.github.com/users/stedolan/repos",113 "organizations_url": "https://api.github.com/users/stedolan/orgs",114 "subscriptions_url": "https://api.github.com/users/stedolan/subscriptions",115 "starred_url": "https://api.github.com/users/stedolan/starred{/owner}{/repo}",115 "following_url": "https://api.github.com/users/stedolan/following{/other_user}",116 "gists_url": "https://api.github.com/users/stedolan/gists{/gist_id}",117 "starred_url": "https://api.github.com/users/stedolan/starred{/owner}{/repo}",118 "subscriptions_url": "https://api.github.com/users/stedolan/subscriptions",119 "organizations_url": "https://api.github.com/users/stedolan/orgs",120 "repos_url": "https://api.github.com/users/stedolan/repos",121 "events_url": "https://api.github.com/users/stedolan/events{/privacy}",122 "received_events_url": "https://api.github.com/users/stedolan/received_events",123 "type": "User",124 "site_admin": false125 },126 "committer": {127 "login": "stedolan",128 "id": 79765,119 "avatar_url": "https://1.gravatar.com/avatar/31de909d8e55dd07ed782d92ece59842?d=https%3A%2F%2Fidenticons.github.com%2Ffc5b6765b1c9cfaecea48ae71df4d279.png",120 "gravatar_id": "31de909d8e55dd07ed782d92ece59842",129 "avatar_url": "https://avatars.githubusercontent.com/u/79765?v=3",130 "gravatar_id": "",131 "url": "https://api.github.com/users/stedolan",132 "html_url": "https://github.com/stedolan",133 "followers_url": "https://api.github.com/users/stedolan/followers",124 "following_url": "https://api.github.com/users/stedolan/following{/other_user}"134 "following_url": "https://api.github.com/users/stedolan/following{/other_user}",135 "gists_url": "https://api.github.com/users/stedolan/gists{/gist_id}",136 "starred_url": "https://api.github.com/users/stedolan/starred{/owner}{/repo}",137 "subscriptions_url": "https://api.github.com/users/stedolan/subscriptions",138 "organizations_url": "https://api.github.com/users/stedolan/orgs",139 "repos_url": "https://api.github.com/users/stedolan/repos",140 "events_url": "https://api.github.com/users/stedolan/events{/privacy}",141 "received_events_url": "https://api.github.com/users/stedolan/received_events",142 "type": "User",143 "site_admin": false144 },126 "comments_url": "https://api.github.com/repos/stedolan/jq/commits/d25341478381063d1c76e81b3a52e0592a7c997f/comments",127 "html_url": "https://github.com/stedolan/jq/commit/d25341478381063d1c76e81b3a52e0592a7c997f",128 "url": "https://api.github.com/repos/stedolan/jq/commits/d25341478381063d1c76e81b3a52e0592a7c997f",129 "commit": {130 "comment_count": 0,131 "url": "https://api.github.com/repos/stedolan/jq/git/commits/d25341478381063d1c76e81b3a52e0592a7c997f",132 "tree": {133 "url": "https://api.github.com/repos/stedolan/jq/git/trees/6ab697a8dfb5a96e124666bf6d6213822599fb40",134 "sha": "6ab697a8dfb5a96e124666bf6d6213822599fb40"145 "parents": [146 {147 "sha": "54b9c9bdb225af5d886466d72f47eafc51acb4f7",148 "url": "https://api.github.com/repos/stedolan/jq/commits/54b9c9bdb225af5d886466d72f47eafc51acb4f7",149 "html_url": "https://github.com/stedolan/jq/commit/54b9c9bdb225af5d886466d72f47eafc51acb4f7"150 },136 "message": "Merge pull request #162 from stedolan/utf8-fixes\n\nUtf8 fixes. Closes #161",137 "committer": {138 "date": "2013-06-22T16:30:59Z",139 "email": "mu@netsoc.tcd.ie",140 "name": "Stephen Dolan"141 },142 "author": {143 "date": "2013-06-22T16:30:59Z",144 "email": "mu@netsoc.tcd.ie",145 "name": "Stephen Dolan"151 {152 "sha": "8b1b503609c161fea4b003a7179b3fbb2dd4345a",153 "url": "https://api.github.com/repos/stedolan/jq/commits/8b1b503609c161fea4b003a7179b3fbb2dd4345a",154 "html_url": "https://github.com/stedolan/jq/commit/8b1b503609c161fea4b003a7179b3fbb2dd4345a"155 }147 },148 "sha": "d25341478381063d1c76e81b3a52e0592a7c997f"156 ]157 }158159 - text: |160153 For the rest of the examples, I'll leave out the `curl` command - it's not going to change.161 For the rest of the examples, I'll leave out the `curl` command - it's not162 going to change.163155 There's still a lot of info we don't care about there, so we'll156 restrict it down to the most interesting fields.164 There's a lot of info we don't care about there, so we'll restrict it down165 to the most interesting fields.166158167 - command: "jq '.[0] | {message: .commit.message, name: .commit.committer.name}'"168 result: |169 {162 "name": "Stephen Dolan",163 "message": "Merge pull request #162 from stedolan/utf8-fixes\n\nUtf8 fixes. Closes #161"170 "message": "Merge pull request #162 from stedolan/utf8-fixes\n\nUtf8 fixes. Closes #161",171 "name": "Stephen Dolan"172 }173174 - text: |175168 The `|` operator in jq feeds the output of one filter169 (`.[0]` which gets the first element of the array in the response)170 into the input of another (`{...}` which171 builds an object out of those fields). You can access nested attributes,172 such as `.commit.message`:176 The `|` operator in jq feeds the output of one filter (`.[0]` which gets177 the first element of the array in the response) into the input of another178 (`{...}` which builds an object out of those fields). You can access179 nested attributes, such as `.commit.message`.180174 Now let's get the rest of the commits:181 Now let's get the rest of the commits.182176183 - command: "jq '.[] | {message: .commit.message, name: .commit.committer.name}'"184 result: |185 {180 "name": "Stephen Dolan",181 "message": "Merge pull request #162 from stedolan/utf8-fixes\n\nUtf8 fixes. Closes #161"186 "message": "Merge pull request #162 from stedolan/utf8-fixes\n\nUtf8 fixes. Closes #161",187 "name": "Stephen Dolan"188 }189 {184 "name": "Stephen Dolan",185 "message": "Reject all overlong UTF8 sequences."190 "message": "Reject all overlong UTF8 sequences.",191 "name": "Stephen Dolan"192 }193 {188 "name": "Stephen Dolan",189 "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."194 "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.",195 "name": "Stephen Dolan"196 }197 {192 "name": "Stephen Dolan",193 "message": "Fix example in manual for `floor`. See #155."198 "message": "Fix example in manual for `floor`. See #155.",199 "name": "Stephen Dolan"200 }201 {196 "name": "Nicolas Williams",197 "message": "Document floor"202 "message": "Document floor",203 "name": "Nicolas Williams"204 }205206 - text: |207202 `.[]` returns each element of the array returned in the response,203 one at a time, which are all fed into `{message: .commit.message, name: .commit.committer.name}`.208 `.[]` returns each element of the array returned in the response, one at a209 time, which are all fed into210 `{message: .commit.message, name: .commit.committer.name}`.211205212 Data in jq is represented as streams of JSON values - every jq213 expression runs for each value in its input stream, and can214 produce any number of values to its output stream.215
8 unmodified lines
224 - command: "jq '[.[] | {message: .commit.message, name: .commit.committer.name}]'"225 result: |226 [227 {222 "name": "Stephen Dolan",223 "message": "Merge pull request #162 from stedolan/utf8-fixes\n\nUtf8 fixes. Closes #161"228 "message": "Merge pull request #163 from stedolan/utf8-fixes\n\nUtf8 fixes. Closes #161",229 "name": "Stephen Dolan"230 },231 {226 "name": "Stephen Dolan",227 "message": "Reject all overlong UTF8 sequences."232 "message": "Reject all overlong UTF8 sequences.",233 "name": "Stephen Dolan"234 },235 {230 "name": "Stephen Dolan",231 "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."236 "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.",237 "name": "Stephen Dolan"238 },239 {234 "name": "Stephen Dolan",235 "message": "Fix example in manual for `floor`. See #155."240 "message": "Fix example in manual for `floor`. See #155.",241 "name": "Stephen Dolan"242 },243 {238 "name": "Nicolas Williams",239 "message": "Document floor"244 "message": "Document floor",245 "name": "Nicolas Williams"246 }247 ]248249 - text: |250251 - - -252
2 unmodified lines
255 about "parent" commits. There can be one or many.256257 "parents": [258 {252 "html_url": "https://github.com/stedolan/jq/commit/54b9c9bdb225af5d886466d72f47eafc51acb4f7",259 "sha": "54b9c9bdb225af5d886466d72f47eafc51acb4f7",260 "url": "https://api.github.com/repos/stedolan/jq/commits/54b9c9bdb225af5d886466d72f47eafc51acb4f7",254 "sha": "54b9c9bdb225af5d886466d72f47eafc51acb4f7"261 "html_url": "https://github.com/stedolan/jq/commit/54b9c9bdb225af5d886466d72f47eafc51acb4f7"262 },263 {257 "html_url": "https://github.com/stedolan/jq/commit/8b1b503609c161fea4b003a7179b3fbb2dd4345a",264 "sha": "8b1b503609c161fea4b003a7179b3fbb2dd4345a",265 "url": "https://api.github.com/repos/stedolan/jq/commits/8b1b503609c161fea4b003a7179b3fbb2dd4345a",259 "sha": "8b1b503609c161fea4b003a7179b3fbb2dd4345a"266 "html_url": "https://github.com/stedolan/jq/commit/8b1b503609c161fea4b003a7179b3fbb2dd4345a"267 }268 ]269270 We want to pull out all of the "html_url" fields inside that array of parent271 commits and make a simple list of strings to go along with the272 "message" and "author" fields we already have.273267268274 - command: "jq '[.[] | {message: .commit.message, name: .commit.committer.name, parents: [.parents[].html_url]}]'"275 result: |276 [277 {278 "message": "Merge pull request #162 from stedolan/utf8-fixes\n\nUtf8 fixes. Closes #161",279 "name": "Stephen Dolan",280 "parents": [281 "https://github.com/stedolan/jq/commit/54b9c9bdb225af5d886466d72f47eafc51acb4f7",282 "https://github.com/stedolan/jq/commit/8b1b503609c161fea4b003a7179b3fbb2dd4345a"276 ],277 "name": "Stephen Dolan",278 "message": "Merge pull request #162 from stedolan/utf8-fixes\n\nUtf8 fixes. Closes #161"283 ]284 },285 {286 "message": "Reject all overlong UTF8 sequences.",287 "name": "Stephen Dolan",288 "parents": [289 "https://github.com/stedolan/jq/commit/ff48bd6ec538b01d1057be8e93b94eef6914e9ef"283 ],284 "name": "Stephen Dolan",285 "message": "Reject all overlong UTF8 sequences."290 ]291 },292 {293 "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.",294 "name": "Stephen Dolan",295 "parents": [296 "https://github.com/stedolan/jq/commit/54b9c9bdb225af5d886466d72f47eafc51acb4f7"290 ],291 "name": "Stephen Dolan",292 "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."297 ]298 },299 {300 "message": "Fix example in manual for `floor`. See #155.",301 "name": "Stephen Dolan",302 "parents": [303 "https://github.com/stedolan/jq/commit/3dcdc582ea993afea3f5503a78a77675967ecdfa"297 ],298 "name": "Stephen Dolan",299 "message": "Fix example in manual for `floor`. See #155."304 ]305 },306 {307 "message": "Document floor",308 "name": "Nicolas Williams",309 "parents": [310 "https://github.com/stedolan/jq/commit/7c4171d414f647ab08bcd20c76a4d8ed68d9c602"304 ],305 "name": "Nicolas Williams",306 "message": "Document floor"311 ]312 }313 ]314315 - text: |316317 Here we're making an object as before, but this time the `parents`313 field is being set to `[.parents[].html_url]}]`, which collects318 field is being set to `[.parents[].html_url]`, which collects319 all of the parent commit URLs defined in the parents object.320321 - text: |322323 - - -324320 Here endeth the tutorial! There's lots more to play with, go325 Here endeth the tutorial! There's lots more to play with. Go326 read [the manual](../manual/) if you're interested, and [download327 jq](../download/) if you haven't already.