jq 用法
GitHub has a JSON API, so let's play with that. This URL gets us the last 5 commits from the jq repo.
## 方式0
curl 'https://api.github.com/repos/stedolan/jq/commits?per_page=5'
## 方式1
curl 'https://api.github.com/repos/stedolan/jq/commits?per_page=5' | jq '.'
## 方式2
curl 'https://api.github.com/repos/stedolan/jq/commits?per_page=5' | jq '.[0]'
## 方式3
curl 'https://api.github.com/repos/stedolan/jq/commits?per_page=5' | jq '.[0] | {message: .commit.message, name: .commit.committer.name}'
## 方式4
curl 'https://api.github.com/repos/stedolan/jq/commits?per_page=5' | jq '.[] | {message: .commit.message, name: .commit.committer.name}'
## 方式5
curl 'https://api.github.com/repos/stedolan/jq/commits?per_page=5' | jq '[.[] | {message: .commit.message, name: .commit.committer.name}]'
## 方式6
curl 'https://api.github.com/repos/stedolan/jq/commits?per_page=5' | jq '[.[] | {message: .commit.message, name: .commit.committer.name, parents: [.parents[].html_url]}]'
1、网络请求原始数据
# 操作
curl 'https://api.github.com/repos/stedolan/jq/commits?per_page=5'
# 响应
[
{
"sha": "a9f97e9e61a910a374a5d768244e8ad63f407d3e",
"node_id": "C_kwDOAE3WVdoAKGE5Zjk3ZTllNjFhOTEwYTM3NGE1ZDc2ODI0NGU4YWQ2M2Y0MDdkM2U",
"commit": {
"author": {
"name": "Nicolas Williams",
"email": "nico@cryptonector.com",
"date": "2021-10-21T05:17:39Z"
},
"committer": {
"name": "Nicolas Williams",
"email": "nico@cryptonector.com",
"date": "2021-10-24T21:23:26Z"
},
"message": "Fix accidentally quadratic behavior in _modify\n\nWe need to be careful to not grab an extra reference when mutating data\nstructures because that means we make extra copies. Doing that every\ntime in `_modify` is really painful, as that function implements `|=`\nand all modify-assign operators.\n\n`jv_setpath()` also grabs additional references, so this is not the only\nfix needed for the modify-assign operators to not be accidentally\nquadratic.\n\nWe have to use `LOADVN` in order to make this fix possible, so we should\nreally byte-code `_modify` rather than jq-code it. However, as a\nstop-gap to make this fix easier, I'm adding syntax for referring to a\n`$binding` such that you get `LOADVN` instead of `LOADV`.\n\nThis syntax is not meant to be used outside jq's internals! Therefore\nit is not documented. I promise to break it later, so don't use it!\n\nTBD, but later:\n\n - Optimize `_modify` for the case where `update` outputs more than one\n value.\n\n This is trivial: add a `setpath($p; null)` in the middle of `_modify`\n before calling `update`. But unfortunately the VM retains a\n reference to `value_at_path` for path expression checking, and fixing\n that will require more work.",
"tree": {
"sha": "7883361d86bd97b1bcd2299fa5886182b27cee54",
"url": "https://api.github.com/repos/stedolan/jq/git/trees/7883361d86bd97b1bcd2299fa5886182b27cee54"
},
"url": "https://api.github.com/repos/stedolan/jq/git/commits/a9f97e9e61a910a374a5d768244e8ad63f407d3e",
"comment_count": 0,
"verification": {
"verified": false,
"reason": "unsigned",
"signature": null,
"payload": null
}
},
"url": "https://api.github.com/repos/stedolan/jq/commits/a9f97e9e61a910a374a5d768244e8ad63f407d3e",
"html_url": "https://github.com/stedolan/jq/commit/a9f97e9e61a910a374a5d768244e8ad63f407d3e",
"comments_url": "https://api.github.com/repos/stedolan/jq/commits/a9f97e9e61a910a374a5d768244e8ad63f407d3e/comments",
"author": {
"login": "nicowilliams",
"id": 604851,
"node_id": "MDQ6VXNlcjYwNDg1MQ==",
"avatar_url": "https://avatars.githubusercontent.com/u/604851?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/nicowilliams",
"html_url": "https://github.com/nicowilliams",
"followers_url": "https://api.github.com/users/nicowilliams/followers",
"following_url": "https://api.github.com/users/nicowilliams/following{/other_user}",
"gists_url": "https://api.github.com/users/nicowilliams/gists{/gist_id}",
"starred_url": "https://api.github.com/users/nicowilliams/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/nicowilliams/subscriptions",
"organizations_url": "https://api.github.com/users/nicowilliams/orgs",
"repos_url": "https://api.github.com/users/nicowilliams/repos",
"events_url": "https://api.github.com/users/nicowilliams/events{/privacy}",
"received_events_url": "https://api.github.com/users/nicowilliams/received_events",
"type": "User",
"site_admin": false
},
"committer": {
"login": "nicowilliams",
"id": 604851,
"node_id": "MDQ6VXNlcjYwNDg1MQ==",
"avatar_url": "https://avatars.githubusercontent.com/u/604851?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/nicowilliams",
"html_url": "https://github.com/nicowilliams",
"followers_url": "https://api.github.com/users/nicowilliams/followers",
"following_url": "https://api.github.com/users/nicowilliams/following{/other_user}",
"gists_url": "https://api.github.com/users/nicowilliams/gists{/gist_id}",
"starred_url": "https://api.github.com/users/nicowilliams/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/nicowilliams/subscriptions",
"organizations_url": "https://api.github.com/users/nicowilliams/orgs",
"repos_url": "https://api.github.com/users/nicowilliams/repos",
"events_url": "https://api.github.com/users/nicowilliams/events{/privacy}",
"received_events_url": "https://api.github.com/users/nicowilliams/received_events",
"type": "User",
"site_admin": false
},
"parents": [
{
"sha": "0c3455d3290fa03da8c01c135dd7126a80ed28a8",
"url": "https://api.github.com/repos/stedolan/jq/commits/0c3455d3290fa03da8c01c135dd7126a80ed28a8",
"html_url": "https://github.com/stedolan/jq/commit/0c3455d3290fa03da8c01c135dd7126a80ed28a8"
}
]
},
{
"sha": "0c3455d3290fa03da8c01c135dd7126a80ed28a8",
"node_id": "C_kwDOAE3WVdoAKDBjMzQ1NWQzMjkwZmEwM2RhOGMwMWMxMzVkZDcxMjZhODBlZDI4YTg",
"commit": {
"author": {
"name": "Nicolas Williams",
"email": "nico@cryptonector.com",
"date": "2021-10-21T05:15:12Z"
},
"committer": {
"name": "Nicolas Williams",
"email": "nico@cryptonector.com",
"date": "2021-10-24T21:23:26Z"
},
"message": "Fix accidentally quadratic behavior in setpath\n\nWe need to be careful to not grab an extra reference when mutating\ndata structures because that means we make extra copies. Doing that\nevery time in `jv_setpath()` is really painful, as that function is used\nin `_modify/2`, which is used in `|=` and all modify-assign operators.\n\n`_modify` also grabs additional references, so this is not the only fix\nneeded for the modify-assign operators to not be accidentally quadratic.",
"tree": {
"sha": "2afb78228b16aaf0d28d5118edb8daab3b79234b",
"url": "https://api.github.com/repos/stedolan/jq/git/trees/2afb78228b16aaf0d28d5118edb8daab3b79234b"
},
"url": "https://api.github.com/repos/stedolan/jq/git/commits/0c3455d3290fa03da8c01c135dd7126a80ed28a8",
"comment_count": 0,
"verification": {
"verified": false,
"reason": "unsigned",
"signature": null,
"payload": null
}
},
"url": "https://api.github.com/repos/stedolan/jq/commits/0c3455d3290fa03da8c01c135dd7126a80ed28a8",
"html_url": "https://github.com/stedolan/jq/commit/0c3455d3290fa03da8c01c135dd7126a80ed28a8",
"comments_url": "https://api.github.com/repos/stedolan/jq/commits/0c3455d3290fa03da8c01c135dd7126a80ed28a8/comments",
"author": {
"login": "nicowilliams",
"id": 604851,
"node_id": "MDQ6VXNlcjYwNDg1MQ==",
"avatar_url": "https://avatars.githubusercontent.com/u/604851?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/nicowilliams",
"html_url": "https://github.com/nicowilliams",
"followers_url": "https://api.github.com/users/nicowilliams/followers",
"following_url": "https://api.github.com/users/nicowilliams/following{/other_user}",
"gists_url": "https://api.github.com/users/nicowilliams/gists{/gist_id}",
"starred_url": "https://api.github.com/users/nicowilliams/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/nicowilliams/subscriptions",
"organizations_url": "https://api.github.com/users/nicowilliams/orgs",
"repos_url": "https://api.github.com/users/nicowilliams/repos",
"events_url": "https://api.github.com/users/nicowilliams/events{/privacy}",
"received_events_url": "https://api.github.com/users/nicowilliams/received_events",
"type": "User",
"site_admin": false
},
"committer": {
"login": "nicowilliams",
"id": 604851,
"node_id": "MDQ6VXNlcjYwNDg1MQ==",
"avatar_url": "https://avatars.githubusercontent.com/u/604851?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/nicowilliams",
"html_url": "https://github.com/nicowilliams",
"followers_url": "https://api.github.com/users/nicowilliams/followers",
"following_url": "https://api.github.com/users/nicowilliams/following{/other_user}",
"gists_url": "https://api.github.com/users/nicowilliams/gists{/gist_id}",
"starred_url": "https://api.github.com/users/nicowilliams/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/nicowilliams/subscriptions",
"organizations_url": "https://api.github.com/users/nicowilliams/orgs",
"repos_url": "https://api.github.com/users/nicowilliams/repos",
"events_url": "https://api.github.com/users/nicowilliams/events{/privacy}",
"received_events_url": "https://api.github.com/users/nicowilliams/received_events",
"type": "User",
"site_admin": false
},
"parents": [
{
"sha": "1a1804afcb88cdc3f1f0e74e83385146b55ae205",
"url": "https://api.github.com/repos/stedolan/jq/commits/1a1804afcb88cdc3f1f0e74e83385146b55ae205",
"html_url": "https://github.com/stedolan/jq/commit/1a1804afcb88cdc3f1f0e74e83385146b55ae205"
}
]
},
{
"sha": "1a1804afcb88cdc3f1f0e74e83385146b55ae205",
"node_id": "C_kwDOAE3WVdoAKDFhMTgwNGFmY2I4OGNkYzNmMWYwZTc0ZTgzMzg1MTQ2YjU1YWUyMDU",
"commit": {
"author": {
"name": "Nicolas Williams",
"email": "nico@cryptonector.com",
"date": "2021-10-24T20:26:08Z"
},
"committer": {
"name": "Nicolas Williams",
"email": "nico@cryptonector.com",
"date": "2021-10-24T21:23:26Z"
},
"message": "Fix LOADV/LOADVN refcount printing",
"tree": {
"sha": "bff7daeb282547034e7198b0f645e52142a1af11",
"url": "https://api.github.com/repos/stedolan/jq/git/trees/bff7daeb282547034e7198b0f645e52142a1af11"
},
"url": "https://api.github.com/repos/stedolan/jq/git/commits/1a1804afcb88cdc3f1f0e74e83385146b55ae205",
"comment_count": 0,
"verification": {
"verified": false,
"reason": "unsigned",
"signature": null,
"payload": null
}
},
"url": "https://api.github.com/repos/stedolan/jq/commits/1a1804afcb88cdc3f1f0e74e83385146b55ae205",
"html_url": "https://github.com/stedolan/jq/commit/1a1804afcb88cdc3f1f0e74e83385146b55ae205",
"comments_url": "https://api.github.com/repos/stedolan/jq/commits/1a1804afcb88cdc3f1f0e74e83385146b55ae205/comments",
"author": {
"login": "nicowilliams",
"id": 604851,
"node_id": "MDQ6VXNlcjYwNDg1MQ==",
"avatar_url": "https://avatars.githubusercontent.com/u/604851?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/nicowilliams",
"html_url": "https://github.com/nicowilliams",
"followers_url": "https://api.github.com/users/nicowilliams/followers",
"following_url": "https://api.github.com/users/nicowilliams/following{/other_user}",
"gists_url": "https://api.github.com/users/nicowilliams/gists{/gist_id}",
"starred_url": "https://api.github.com/users/nicowilliams/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/nicowilliams/subscriptions",
"organizations_url": "https://api.github.com/users/nicowilliams/orgs",
"repos_url": "https://api.github.com/users/nicowilliams/repos",
"events_url": "https://api.github.com/users/nicowilliams/events{/privacy}",
"received_events_url": "https://api.github.com/users/nicowilliams/received_events",
"type": "User",
"site_admin": false
},
"committer": {
"login": "nicowilliams",
"id": 604851,
"node_id": "MDQ6VXNlcjYwNDg1MQ==",
"avatar_url": "https://avatars.githubusercontent.com/u/604851?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/nicowilliams",
"html_url": "https://github.com/nicowilliams",
"followers_url": "https://api.github.com/users/nicowilliams/followers",
"following_url": "https://api.github.com/users/nicowilliams/following{/other_user}",
"gists_url": "https://api.github.com/users/nicowilliams/gists{/gist_id}",
"starred_url": "https://api.github.com/users/nicowilliams/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/nicowilliams/subscriptions",
"organizations_url": "https://api.github.com/users/nicowilliams/orgs",
"repos_url": "https://api.github.com/users/nicowilliams/repos",
"events_url": "https://api.github.com/users/nicowilliams/events{/privacy}",
"received_events_url": "https://api.github.com/users/nicowilliams/received_events",
"type": "User",
"site_admin": false
},
"parents": [
{
"sha": "582717a7b4af6ce0e231b9aee090107235ef2d0f",
"url": "https://api.github.com/repos/stedolan/jq/commits/582717a7b4af6ce0e231b9aee090107235ef2d0f",
"html_url": "https://github.com/stedolan/jq/commit/582717a7b4af6ce0e231b9aee090107235ef2d0f"
}
]
},
{
"sha": "582717a7b4af6ce0e231b9aee090107235ef2d0f",
"node_id": "C_kwDOAE3WVdoAKDU4MjcxN2E3YjRhZjZjZTBlMjMxYjlhZWUwOTAxMDcyMzVlZjJkMGY",
"commit": {
"author": {
"name": "Nicolas Williams",
"email": "nico@cryptonector.com",
"date": "2021-10-21T05:10:47Z"
},
"committer": {
"name": "Nicolas Williams",
"email": "nico@cryptonector.com",
"date": "2021-10-24T21:23:26Z"
},
"message": "Fix crash in LOADVN when stack grows\n\nThis `stack_push()` call in LOADVN invalidates `var`:\n\n jv* var = frame_local_var(jq, v, level);\n jv_free(stack_popn(jq));\n------>stack_push(jq, *var);\n *var = jv_null();\n ^^^^^^\n\nWe have to re-compute `var`:\n\n jv* var = frame_local_var(jq, v, level);\n jv_free(stack_popn(jq));\n stack_push(jq, *var);\n------>var = frame_local_var(jq, v, level);\n *var = jv_null();",
"tree": {
"sha": "b6b5b56c5aab6918c6e19c9154800ffad7edd2b8",
"url": "https://api.github.com/repos/stedolan/jq/git/trees/b6b5b56c5aab6918c6e19c9154800ffad7edd2b8"
},
"url": "https://api.github.com/repos/stedolan/jq/git/commits/582717a7b4af6ce0e231b9aee090107235ef2d0f",
"comment_count": 0,
"verification": {
"verified": false,
"reason": "unsigned",
"signature": null,
"payload": null
}
},
"url": "https://api.github.com/repos/stedolan/jq/commits/582717a7b4af6ce0e231b9aee090107235ef2d0f",
"html_url": "https://github.com/stedolan/jq/commit/582717a7b4af6ce0e231b9aee090107235ef2d0f",
"comments_url": "https://api.github.com/repos/stedolan/jq/commits/582717a7b4af6ce0e231b9aee090107235ef2d0f/comments",
"author": {
"login": "nicowilliams",
"id": 604851,
"node_id": "MDQ6VXNlcjYwNDg1MQ==",
"avatar_url": "https://avatars.githubusercontent.com/u/604851?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/nicowilliams",
"html_url": "https://github.com/nicowilliams",
"followers_url": "https://api.github.com/users/nicowilliams/followers",
"following_url": "https://api.github.com/users/nicowilliams/following{/other_user}",
"gists_url": "https://api.github.com/users/nicowilliams/gists{/gist_id}",
"starred_url": "https://api.github.com/users/nicowilliams/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/nicowilliams/subscriptions",
"organizations_url": "https://api.github.com/users/nicowilliams/orgs",
"repos_url": "https://api.github.com/users/nicowilliams/repos",
"events_url": "https://api.github.com/users/nicowilliams/events{/privacy}",
"received_events_url": "https://api.github.com/users/nicowilliams/received_events",
"type": "User",
"site_admin": false
},
"committer": {
"login": "nicowilliams",
"id": 604851,
"node_id": "MDQ6VXNlcjYwNDg1MQ==",
"avatar_url": "https://avatars.githubusercontent.com/u/604851?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/nicowilliams",
"html_url": "https://github.com/nicowilliams",
"followers_url": "https://api.github.com/users/nicowilliams/followers",
"following_url": "https://api.github.com/users/nicowilliams/following{/other_user}",
"gists_url": "https://api.github.com/users/nicowilliams/gists{/gist_id}",
"starred_url": "https://api.github.com/users/nicowilliams/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/nicowilliams/subscriptions",
"organizations_url": "https://api.github.com/users/nicowilliams/orgs",
"repos_url": "https://api.github.com/users/nicowilliams/repos",
"events_url": "https://api.github.com/users/nicowilliams/events{/privacy}",
"received_events_url": "https://api.github.com/users/nicowilliams/received_events",
"type": "User",
"site_admin": false
},
"parents": [
{
"sha": "07dc653ae151a8320646a1c955839fb88d4a5546",
"url": "https://api.github.com/repos/stedolan/jq/commits/07dc653ae151a8320646a1c955839fb88d4a5546",
"html_url": "https://github.com/stedolan/jq/commit/07dc653ae151a8320646a1c955839fb88d4a5546"
}
]
},
{
"sha": "07dc653ae151a8320646a1c955839fb88d4a5546",
"node_id": "C_kwDOAE3WVdoAKDA3ZGM2NTNhZTE1MWE4MzIwNjQ2YTFjOTU1ODM5ZmI4OGQ0YTU1NDY",
"commit": {
"author": {
"name": "Nicolas Williams",
"email": "nico@cryptonector.com",
"date": "2021-10-24T20:59:57Z"
},
"committer": {
"name": "Nicolas Williams",
"email": "nico@cryptonector.com",
"date": "2021-10-24T21:23:26Z"
},
"message": "Appveyor: Get Appveyor building again",
"tree": {
"sha": "eb6189c146e19171ae99a80a23e6dd64dc408c1b",
"url": "https://api.github.com/repos/stedolan/jq/git/trees/eb6189c146e19171ae99a80a23e6dd64dc408c1b"
},
"url": "https://api.github.com/repos/stedolan/jq/git/commits/07dc653ae151a8320646a1c955839fb88d4a5546",
"comment_count": 0,
"verification": {
"verified": false,
"reason": "unsigned",
"signature": null,
"payload": null
}
},
"url": "https://api.github.com/repos/stedolan/jq/commits/07dc653ae151a8320646a1c955839fb88d4a5546",
"html_url": "https://github.com/stedolan/jq/commit/07dc653ae151a8320646a1c955839fb88d4a5546",
"comments_url": "https://api.github.com/repos/stedolan/jq/commits/07dc653ae151a8320646a1c955839fb88d4a5546/comments",
"author": {
"login": "nicowilliams",
"id": 604851,
"node_id": "MDQ6VXNlcjYwNDg1MQ==",
"avatar_url": "https://avatars.githubusercontent.com/u/604851?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/nicowilliams",
"html_url": "https://github.com/nicowilliams",
"followers_url": "https://api.github.com/users/nicowilliams/followers",
"following_url": "https://api.github.com/users/nicowilliams/following{/other_user}",
"gists_url": "https://api.github.com/users/nicowilliams/gists{/gist_id}",
"starred_url": "https://api.github.com/users/nicowilliams/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/nicowilliams/subscriptions",
"organizations_url": "https://api.github.com/users/nicowilliams/orgs",
"repos_url": "https://api.github.com/users/nicowilliams/repos",
"events_url": "https://api.github.com/users/nicowilliams/events{/privacy}",
"received_events_url": "https://api.github.com/users/nicowilliams/received_events",
"type": "User",
"site_admin": false
},
"committer": {
"login": "nicowilliams",
"id": 604851,
"node_id": "MDQ6VXNlcjYwNDg1MQ==",
"avatar_url": "https://avatars.githubusercontent.com/u/604851?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/nicowilliams",
"html_url": "https://github.com/nicowilliams",
"followers_url": "https://api.github.com/users/nicowilliams/followers",
"following_url": "https://api.github.com/users/nicowilliams/following{/other_user}",
"gists_url": "https://api.github.com/users/nicowilliams/gists{/gist_id}",
"starred_url": "https://api.github.com/users/nicowilliams/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/nicowilliams/subscriptions",
"organizations_url": "https://api.github.com/users/nicowilliams/orgs",
"repos_url": "https://api.github.com/users/nicowilliams/repos",
"events_url": "https://api.github.com/users/nicowilliams/events{/privacy}",
"received_events_url": "https://api.github.com/users/nicowilliams/received_events",
"type": "User",
"site_admin": false
},
"parents": [
{
"sha": "d79fe7fd582fe0dfdb253445e8ccd671d6fdf8b6",
"url": "https://api.github.com/repos/stedolan/jq/commits/d79fe7fd582fe0dfdb253445e8ccd671d6fdf8b6",
"html_url": "https://github.com/stedolan/jq/commit/d79fe7fd582fe0dfdb253445e8ccd671d6fdf8b6"
}
]
}
]
2、jq 格式化json
# 操作
curl 'https://api.github.com/repos/stedolan/jq/commits?per_page=5' | jq '.'
# 响应
[
{
"sha": "a9f97e9e61a910a374a5d768244e8ad63f407d3e",
"node_id": "C_kwDOAE3WVdoAKGE5Zjk3ZTllNjFhOTEwYTM3NGE1ZDc2ODI0NGU4YWQ2M2Y0MDdkM2U",
"commit": {
"author": {
"name": "Nicolas Williams",
"email": "nico@cryptonector.com",
"date": "2021-10-21T05:17:39Z"
},
"committer": {
"name": "Nicolas Williams",
"email": "nico@cryptonector.com",
"date": "2021-10-24T21:23:26Z"
},
"message": "Fix accidentally quadratic behavior in _modify\n\nWe need to be careful to not grab an extra reference when mutating data\nstructures because that means we make extra copies. Doing that every\ntime in `_modify` is really painful, as that function implements `|=`\nand all modify-assign operators.\n\n`jv_setpath()` also grabs additional references, so this is not the only\nfix needed for the modify-assign operators to not be accidentally\nquadratic.\n\nWe have to use `LOADVN` in order to make this fix possible, so we should\nreally byte-code `_modify` rather than jq-code it. However, as a\nstop-gap to make this fix easier, I'm adding syntax for referring to a\n`$binding` such that you get `LOADVN` instead of `LOADV`.\n\nThis syntax is not meant to be used outside jq's internals! Therefore\nit is not documented. I promise to break it later, so don't use it!\n\nTBD, but later:\n\n - Optimize `_modify` for the case where `update` outputs more than one\n value.\n\n This is trivial: add a `setpath($p; null)` in the middle of `_modify`\n before calling `update`. But unfortunately the VM retains a\n reference to `value_at_path` for path expression checking, and fixing\n that will require more work.",
"tree": {
"sha": "7883361d86bd97b1bcd2299fa5886182b27cee54",
"url": "https://api.github.com/repos/stedolan/jq/git/trees/7883361d86bd97b1bcd2299fa5886182b27cee54"
},
"url": "https://api.github.com/repos/stedolan/jq/git/commits/a9f97e9e61a910a374a5d768244e8ad63f407d3e",
"comment_count": 0,
"verification": {
"verified": false,
"reason": "unsigned",
"signature": null,
"payload": null
}
},
"url": "https://api.github.com/repos/stedolan/jq/commits/a9f97e9e61a910a374a5d768244e8ad63f407d3e",
"html_url": "https://github.com/stedolan/jq/commit/a9f97e9e61a910a374a5d768244e8ad63f407d3e",
"comments_url": "https://api.github.com/repos/stedolan/jq/commits/a9f97e9e61a910a374a5d768244e8ad63f407d3e/comments",
"author": {
"login": "nicowilliams",
"id": 604851,
"node_id": "MDQ6VXNlcjYwNDg1MQ==",
"avatar_url": "https://avatars.githubusercontent.com/u/604851?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/nicowilliams",
"html_url": "https://github.com/nicowilliams",
"followers_url": "https://api.github.com/users/nicowilliams/followers",
"following_url": "https://api.github.com/users/nicowilliams/following{/other_user}",
"gists_url": "https://api.github.com/users/nicowilliams/gists{/gist_id}",
"starred_url": "https://api.github.com/users/nicowilliams/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/nicowilliams/subscriptions",
"organizations_url": "https://api.github.com/users/nicowilliams/orgs",
"repos_url": "https://api.github.com/users/nicowilliams/repos",
"events_url": "https://api.github.com/users/nicowilliams/events{/privacy}",
"received_events_url": "https://api.github.com/users/nicowilliams/received_events",
"type": "User",
"site_admin": false
},
"committer": {
"login": "nicowilliams",
"id": 604851,
"node_id": "MDQ6VXNlcjYwNDg1MQ==",
"avatar_url": "https://avatars.githubusercontent.com/u/604851?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/nicowilliams",
"html_url": "https://github.com/nicowilliams",
"followers_url": "https://api.github.com/users/nicowilliams/followers",
"following_url": "https://api.github.com/users/nicowilliams/following{/other_user}",
"gists_url": "https://api.github.com/users/nicowilliams/gists{/gist_id}",
"starred_url": "https://api.github.com/users/nicowilliams/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/nicowilliams/subscriptions",
"organizations_url": "https://api.github.com/users/nicowilliams/orgs",
"repos_url": "https://api.github.com/users/nicowilliams/repos",
"events_url": "https://api.github.com/users/nicowilliams/events{/privacy}",
"received_events_url": "https://api.github.com/users/nicowilliams/received_events",
"type": "User",
"site_admin": false
},
"parents": [
{
"sha": "0c3455d3290fa03da8c01c135dd7126a80ed28a8",
"url": "https://api.github.com/repos/stedolan/jq/commits/0c3455d3290fa03da8c01c135dd7126a80ed28a8",
"html_url": "https://github.com/stedolan/jq/commit/0c3455d3290fa03da8c01c135dd7126a80ed28a8"
}
]
},
{
"sha": "0c3455d3290fa03da8c01c135dd7126a80ed28a8",
"node_id": "C_kwDOAE3WVdoAKDBjMzQ1NWQzMjkwZmEwM2RhOGMwMWMxMzVkZDcxMjZhODBlZDI4YTg",
"commit": {
"author": {
"name": "Nicolas Williams",
"email": "nico@cryptonector.com",
"date": "2021-10-21T05:15:12Z"
},
"committer": {
"name": "Nicolas Williams",
"email": "nico@cryptonector.com",
"date": "2021-10-24T21:23:26Z"
},
"message": "Fix accidentally quadratic behavior in setpath\n\nWe need to be careful to not grab an extra reference when mutating\ndata structures because that means we make extra copies. Doing that\nevery time in `jv_setpath()` is really painful, as that function is used\nin `_modify/2`, which is used in `|=` and all modify-assign operators.\n\n`_modify` also grabs additional references, so this is not the only fix\nneeded for the modify-assign operators to not be accidentally quadratic.",
"tree": {
"sha": "2afb78228b16aaf0d28d5118edb8daab3b79234b",
"url": "https://api.github.com/repos/stedolan/jq/git/trees/2afb78228b16aaf0d28d5118edb8daab3b79234b"
},
"url": "https://api.github.com/repos/stedolan/jq/git/commits/0c3455d3290fa03da8c01c135dd7126a80ed28a8",
"comment_count": 0,
"verification": {
"verified": false,
"reason": "unsigned",
"signature": null,
"payload": null
}
},
"url": "https://api.github.com/repos/stedolan/jq/commits/0c3455d3290fa03da8c01c135dd7126a80ed28a8",
"html_url": "https://github.com/stedolan/jq/commit/0c3455d3290fa03da8c01c135dd7126a80ed28a8",
"comments_url": "https://api.github.com/repos/stedolan/jq/commits/0c3455d3290fa03da8c01c135dd7126a80ed28a8/comments",
"author": {
"login": "nicowilliams",
"id": 604851,
"node_id": "MDQ6VXNlcjYwNDg1MQ==",
"avatar_url": "https://avatars.githubusercontent.com/u/604851?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/nicowilliams",
"html_url": "https://github.com/nicowilliams",
"followers_url": "https://api.github.com/users/nicowilliams/followers",
"following_url": "https://api.github.com/users/nicowilliams/following{/other_user}",
"gists_url": "https://api.github.com/users/nicowilliams/gists{/gist_id}",
"starred_url": "https://api.github.com/users/nicowilliams/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/nicowilliams/subscriptions",
"organizations_url": "https://api.github.com/users/nicowilliams/orgs",
"repos_url": "https://api.github.com/users/nicowilliams/repos",
"events_url": "https://api.github.com/users/nicowilliams/events{/privacy}",
"received_events_url": "https://api.github.com/users/nicowilliams/received_events",
"type": "User",
"site_admin": false
},
"committer": {
"login": "nicowilliams",
"id": 604851,
"node_id": "MDQ6VXNlcjYwNDg1MQ==",
"avatar_url": "https://avatars.githubusercontent.com/u/604851?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/nicowilliams",
"html_url": "https://github.com/nicowilliams",
"followers_url": "https://api.github.com/users/nicowilliams/followers",
"following_url": "https://api.github.com/users/nicowilliams/following{/other_user}",
"gists_url": "https://api.github.com/users/nicowilliams/gists{/gist_id}",
"starred_url": "https://api.github.com/users/nicowilliams/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/nicowilliams/subscriptions",
"organizations_url": "https://api.github.com/users/nicowilliams/orgs",
"repos_url": "https://api.github.com/users/nicowilliams/repos",
"events_url": "https://api.github.com/users/nicowilliams/events{/privacy}",
"received_events_url": "https://api.github.com/users/nicowilliams/received_events",
"type": "User",
"site_admin": false
},
"parents": [
{
"sha": "1a1804afcb88cdc3f1f0e74e83385146b55ae205",
"url": "https://api.github.com/repos/stedolan/jq/commits/1a1804afcb88cdc3f1f0e74e83385146b55ae205",
"html_url": "https://github.com/stedolan/jq/commit/1a1804afcb88cdc3f1f0e74e83385146b55ae205"
}
]
},
{
"sha": "1a1804afcb88cdc3f1f0e74e83385146b55ae205",
"node_id": "C_kwDOAE3WVdoAKDFhMTgwNGFmY2I4OGNkYzNmMWYwZTc0ZTgzMzg1MTQ2YjU1YWUyMDU",
"commit": {
"author": {
"name": "Nicolas Williams",
"email": "nico@cryptonector.com",
"date": "2021-10-24T20:26:08Z"
},
"committer": {
"name": "Nicolas Williams",
"email": "nico@cryptonector.com",
"date": "2021-10-24T21:23:26Z"
},
"message": "Fix LOADV/LOADVN refcount printing",
"tree": {
"sha": "bff7daeb282547034e7198b0f645e52142a1af11",
"url": "https://api.github.com/repos/stedolan/jq/git/trees/bff7daeb282547034e7198b0f645e52142a1af11"
},
"url": "https://api.github.com/repos/stedolan/jq/git/commits/1a1804afcb88cdc3f1f0e74e83385146b55ae205",
"comment_count": 0,
"verification": {
"verified": false,
"reason": "unsigned",
"signature": null,
"payload": null
}
},
"url": "https://api.github.com/repos/stedolan/jq/commits/1a1804afcb88cdc3f1f0e74e83385146b55ae205",
"html_url": "https://github.com/stedolan/jq/commit/1a1804afcb88cdc3f1f0e74e83385146b55ae205",
"comments_url": "https://api.github.com/repos/stedolan/jq/commits/1a1804afcb88cdc3f1f0e74e83385146b55ae205/comments",
"author": {
"login": "nicowilliams",
"id": 604851,
"node_id": "MDQ6VXNlcjYwNDg1MQ==",
"avatar_url": "https://avatars.githubusercontent.com/u/604851?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/nicowilliams",
"html_url": "https://github.com/nicowilliams",
"followers_url": "https://api.github.com/users/nicowilliams/followers",
"following_url": "https://api.github.com/users/nicowilliams/following{/other_user}",
"gists_url": "https://api.github.com/users/nicowilliams/gists{/gist_id}",
"starred_url": "https://api.github.com/users/nicowilliams/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/nicowilliams/subscriptions",
"organizations_url": "https://api.github.com/users/nicowilliams/orgs",
"repos_url": "https://api.github.com/users/nicowilliams/repos",
"events_url": "https://api.github.com/users/nicowilliams/events{/privacy}",
"received_events_url": "https://api.github.com/users/nicowilliams/received_events",
"type": "User",
"site_admin": false
},
"committer": {
"login": "nicowilliams",
"id": 604851,
"node_id": "MDQ6VXNlcjYwNDg1MQ==",
"avatar_url": "https://avatars.githubusercontent.com/u/604851?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/nicowilliams",
"html_url": "https://github.com/nicowilliams",
"followers_url": "https://api.github.com/users/nicowilliams/followers",
"following_url": "https://api.github.com/users/nicowilliams/following{/other_user}",
"gists_url": "https://api.github.com/users/nicowilliams/gists{/gist_id}",
"starred_url": "https://api.github.com/users/nicowilliams/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/nicowilliams/subscriptions",
"organizations_url": "https://api.github.com/users/nicowilliams/orgs",
"repos_url": "https://api.github.com/users/nicowilliams/repos",
"events_url": "https://api.github.com/users/nicowilliams/events{/privacy}",
"received_events_url": "https://api.github.com/users/nicowilliams/received_events",
"type": "User",
"site_admin": false
},
"parents": [
{
"sha": "582717a7b4af6ce0e231b9aee090107235ef2d0f",
"url": "https://api.github.com/repos/stedolan/jq/commits/582717a7b4af6ce0e231b9aee090107235ef2d0f",
"html_url": "https://github.com/stedolan/jq/commit/582717a7b4af6ce0e231b9aee090107235ef2d0f"
}
]
},
{
"sha": "582717a7b4af6ce0e231b9aee090107235ef2d0f",
"node_id": "C_kwDOAE3WVdoAKDU4MjcxN2E3YjRhZjZjZTBlMjMxYjlhZWUwOTAxMDcyMzVlZjJkMGY",
"commit": {
"author": {
"name": "Nicolas Williams",
"email": "nico@cryptonector.com",
"date": "2021-10-21T05:10:47Z"
},
"committer": {
"name": "Nicolas Williams",
"email": "nico@cryptonector.com",
"date": "2021-10-24T21:23:26Z"
},
"message": "Fix crash in LOADVN when stack grows\n\nThis `stack_push()` call in LOADVN invalidates `var`:\n\n jv* var = frame_local_var(jq, v, level);\n jv_free(stack_popn(jq));\n------>stack_push(jq, *var);\n *var = jv_null();\n ^^^^^^\n\nWe have to re-compute `var`:\n\n jv* var = frame_local_var(jq, v, level);\n jv_free(stack_popn(jq));\n stack_push(jq, *var);\n------>var = frame_local_var(jq, v, level);\n *var = jv_null();",
"tree": {
"sha": "b6b5b56c5aab6918c6e19c9154800ffad7edd2b8",
"url": "https://api.github.com/repos/stedolan/jq/git/trees/b6b5b56c5aab6918c6e19c9154800ffad7edd2b8"
},
"url": "https://api.github.com/repos/stedolan/jq/git/commits/582717a7b4af6ce0e231b9aee090107235ef2d0f",
"comment_count": 0,
"verification": {
"verified": false,
"reason": "unsigned",
"signature": null,
"payload": null
}
},
"url": "https://api.github.com/repos/stedolan/jq/commits/582717a7b4af6ce0e231b9aee090107235ef2d0f",
"html_url": "https://github.com/stedolan/jq/commit/582717a7b4af6ce0e231b9aee090107235ef2d0f",
"comments_url": "https://api.github.com/repos/stedolan/jq/commits/582717a7b4af6ce0e231b9aee090107235ef2d0f/comments",
"author": {
"login": "nicowilliams",
"id": 604851,
"node_id": "MDQ6VXNlcjYwNDg1MQ==",
"avatar_url": "https://avatars.githubusercontent.com/u/604851?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/nicowilliams",
"html_url": "https://github.com/nicowilliams",
"followers_url": "https://api.github.com/users/nicowilliams/followers",
"following_url": "https://api.github.com/users/nicowilliams/following{/other_user}",
"gists_url": "https://api.github.com/users/nicowilliams/gists{/gist_id}",
"starred_url": "https://api.github.com/users/nicowilliams/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/nicowilliams/subscriptions",
"organizations_url": "https://api.github.com/users/nicowilliams/orgs",
"repos_url": "https://api.github.com/users/nicowilliams/repos",
"events_url": "https://api.github.com/users/nicowilliams/events{/privacy}",
"received_events_url": "https://api.github.com/users/nicowilliams/received_events",
"type": "User",
"site_admin": false
},
"committer": {
"login": "nicowilliams",
"id": 604851,
"node_id": "MDQ6VXNlcjYwNDg1MQ==",
"avatar_url": "https://avatars.githubusercontent.com/u/604851?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/nicowilliams",
"html_url": "https://github.com/nicowilliams",
"followers_url": "https://api.github.com/users/nicowilliams/followers",
"following_url": "https://api.github.com/users/nicowilliams/following{/other_user}",
"gists_url": "https://api.github.com/users/nicowilliams/gists{/gist_id}",
"starred_url": "https://api.github.com/users/nicowilliams/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/nicowilliams/subscriptions",
"organizations_url": "https://api.github.com/users/nicowilliams/orgs",
"repos_url": "https://api.github.com/users/nicowilliams/repos",
"events_url": "https://api.github.com/users/nicowilliams/events{/privacy}",
"received_events_url": "https://api.github.com/users/nicowilliams/received_events",
"type": "User",
"site_admin": false
},
"parents": [
{
"sha": "07dc653ae151a8320646a1c955839fb88d4a5546",
"url": "https://api.github.com/repos/stedolan/jq/commits/07dc653ae151a8320646a1c955839fb88d4a5546",
"html_url": "https://github.com/stedolan/jq/commit/07dc653ae151a8320646a1c955839fb88d4a5546"
}
]
},
{
"sha": "07dc653ae151a8320646a1c955839fb88d4a5546",
"node_id": "C_kwDOAE3WVdoAKDA3ZGM2NTNhZTE1MWE4MzIwNjQ2YTFjOTU1ODM5ZmI4OGQ0YTU1NDY",
"commit": {
"author": {
"name": "Nicolas Williams",
"email": "nico@cryptonector.com",
"date": "2021-10-24T20:59:57Z"
},
"committer": {
"name": "Nicolas Williams",
"email": "nico@cryptonector.com",
"date": "2021-10-24T21:23:26Z"
},
"message": "Appveyor: Get Appveyor building again",
"tree": {
"sha": "eb6189c146e19171ae99a80a23e6dd64dc408c1b",
"url": "https://api.github.com/repos/stedolan/jq/git/trees/eb6189c146e19171ae99a80a23e6dd64dc408c1b"
},
"url": "https://api.github.com/repos/stedolan/jq/git/commits/07dc653ae151a8320646a1c955839fb88d4a5546",
"comment_count": 0,
"verification": {
"verified": false,
"reason": "unsigned",
"signature": null,
"payload": null
}
},
"url": "https://api.github.com/repos/stedolan/jq/commits/07dc653ae151a8320646a1c955839fb88d4a5546",
"html_url": "https://github.com/stedolan/jq/commit/07dc653ae151a8320646a1c955839fb88d4a5546",
"comments_url": "https://api.github.com/repos/stedolan/jq/commits/07dc653ae151a8320646a1c955839fb88d4a5546/comments",
"author": {
"login": "nicowilliams",
"id": 604851,
"node_id": "MDQ6VXNlcjYwNDg1MQ==",
"avatar_url": "https://avatars.githubusercontent.com/u/604851?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/nicowilliams",
"html_url": "https://github.com/nicowilliams",
"followers_url": "https://api.github.com/users/nicowilliams/followers",
"following_url": "https://api.github.com/users/nicowilliams/following{/other_user}",
"gists_url": "https://api.github.com/users/nicowilliams/gists{/gist_id}",
"starred_url": "https://api.github.com/users/nicowilliams/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/nicowilliams/subscriptions",
"organizations_url": "https://api.github.com/users/nicowilliams/orgs",
"repos_url": "https://api.github.com/users/nicowilliams/repos",
"events_url": "https://api.github.com/users/nicowilliams/events{/privacy}",
"received_events_url": "https://api.github.com/users/nicowilliams/received_events",
"type": "User",
"site_admin": false
},
"committer": {
"login": "nicowilliams",
"id": 604851,
"node_id": "MDQ6VXNlcjYwNDg1MQ==",
"avatar_url": "https://avatars.githubusercontent.com/u/604851?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/nicowilliams",
"html_url": "https://github.com/nicowilliams",
"followers_url": "https://api.github.com/users/nicowilliams/followers",
"following_url": "https://api.github.com/users/nicowilliams/following{/other_user}",
"gists_url": "https://api.github.com/users/nicowilliams/gists{/gist_id}",
"starred_url": "https://api.github.com/users/nicowilliams/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/nicowilliams/subscriptions",
"organizations_url": "https://api.github.com/users/nicowilliams/orgs",
"repos_url": "https://api.github.com/users/nicowilliams/repos",
"events_url": "https://api.github.com/users/nicowilliams/events{/privacy}",
"received_events_url": "https://api.github.com/users/nicowilliams/received_events",
"type": "User",
"site_admin": false
},
"parents": [
{
"sha": "d79fe7fd582fe0dfdb253445e8ccd671d6fdf8b6",
"url": "https://api.github.com/repos/stedolan/jq/commits/d79fe7fd582fe0dfdb253445e8ccd671d6fdf8b6",
"html_url": "https://github.com/stedolan/jq/commit/d79fe7fd582fe0dfdb253445e8ccd671d6fdf8b6"
}
]
}
]
3、jq 获取json数组第一个元素
# 操作
curl 'https://api.github.com/repos/stedolan/jq/commits?per_page=5' | jq '.[0]'
# 响应
{
"sha": "a9f97e9e61a910a374a5d768244e8ad63f407d3e",
"node_id": "C_kwDOAE3WVdoAKGE5Zjk3ZTllNjFhOTEwYTM3NGE1ZDc2ODI0NGU4YWQ2M2Y0MDdkM2U",
"commit": {
"author": {
"name": "Nicolas Williams",
"email": "nico@cryptonector.com",
"date": "2021-10-21T05:17:39Z"
},
"committer": {
"name": "Nicolas Williams",
"email": "nico@cryptonector.com",
"date": "2021-10-24T21:23:26Z"
},
"message": "Fix accidentally quadratic behavior in _modify\n\nWe need to be careful to not grab an extra reference when mutating data\nstructures because that means we make extra copies. Doing that every\ntime in `_modify` is really painful, as that function implements `|=`\nand all modify-assign operators.\n\n`jv_setpath()` also grabs additional references, so this is not the only\nfix needed for the modify-assign operators to not be accidentally\nquadratic.\n\nWe have to use `LOADVN` in order to make this fix possible, so we should\nreally byte-code `_modify` rather than jq-code it. However, as a\nstop-gap to make this fix easier, I'm adding syntax for referring to a\n`$binding` such that you get `LOADVN` instead of `LOADV`.\n\nThis syntax is not meant to be used outside jq's internals! Therefore\nit is not documented. I promise to break it later, so don't use it!\n\nTBD, but later:\n\n - Optimize `_modify` for the case where `update` outputs more than one\n value.\n\n This is trivial: add a `setpath($p; null)` in the middle of `_modify`\n before calling `update`. But unfortunately the VM retains a\n reference to `value_at_path` for path expression checking, and fixing\n that will require more work.",
"tree": {
"sha": "7883361d86bd97b1bcd2299fa5886182b27cee54",
"url": "https://api.github.com/repos/stedolan/jq/git/trees/7883361d86bd97b1bcd2299fa5886182b27cee54"
},
"url": "https://api.github.com/repos/stedolan/jq/git/commits/a9f97e9e61a910a374a5d768244e8ad63f407d3e",
"comment_count": 0,
"verification": {
"verified": false,
"reason": "unsigned",
"signature": null,
"payload": null
}
},
"url": "https://api.github.com/repos/stedolan/jq/commits/a9f97e9e61a910a374a5d768244e8ad63f407d3e",
"html_url": "https://github.com/stedolan/jq/commit/a9f97e9e61a910a374a5d768244e8ad63f407d3e",
"comments_url": "https://api.github.com/repos/stedolan/jq/commits/a9f97e9e61a910a374a5d768244e8ad63f407d3e/comments",
"author": {
"login": "nicowilliams",
"id": 604851,
"node_id": "MDQ6VXNlcjYwNDg1MQ==",
"avatar_url": "https://avatars.githubusercontent.com/u/604851?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/nicowilliams",
"html_url": "https://github.com/nicowilliams",
"followers_url": "https://api.github.com/users/nicowilliams/followers",
"following_url": "https://api.github.com/users/nicowilliams/following{/other_user}",
"gists_url": "https://api.github.com/users/nicowilliams/gists{/gist_id}",
"starred_url": "https://api.github.com/users/nicowilliams/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/nicowilliams/subscriptions",
"organizations_url": "https://api.github.com/users/nicowilliams/orgs",
"repos_url": "https://api.github.com/users/nicowilliams/repos",
"events_url": "https://api.github.com/users/nicowilliams/events{/privacy}",
"received_events_url": "https://api.github.com/users/nicowilliams/received_events",
"type": "User",
"site_admin": false
},
"committer": {
"login": "nicowilliams",
"id": 604851,
"node_id": "MDQ6VXNlcjYwNDg1MQ==",
"avatar_url": "https://avatars.githubusercontent.com/u/604851?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/nicowilliams",
"html_url": "https://github.com/nicowilliams",
"followers_url": "https://api.github.com/users/nicowilliams/followers",
"following_url": "https://api.github.com/users/nicowilliams/following{/other_user}",
"gists_url": "https://api.github.com/users/nicowilliams/gists{/gist_id}",
"starred_url": "https://api.github.com/users/nicowilliams/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/nicowilliams/subscriptions",
"organizations_url": "https://api.github.com/users/nicowilliams/orgs",
"repos_url": "https://api.github.com/users/nicowilliams/repos",
"events_url": "https://api.github.com/users/nicowilliams/events{/privacy}",
"received_events_url": "https://api.github.com/users/nicowilliams/received_events",
"type": "User",
"site_admin": false
},
"parents": [
{
"sha": "0c3455d3290fa03da8c01c135dd7126a80ed28a8",
"url": "https://api.github.com/repos/stedolan/jq/commits/0c3455d3290fa03da8c01c135dd7126a80ed28a8",
"html_url": "https://github.com/stedolan/jq/commit/0c3455d3290fa03da8c01c135dd7126a80ed28a8"
}
]
}
4、jq 获取json指定元素的指定字段
# 操作
curl 'https://api.github.com/repos/stedolan/jq/commits?per_page=5' | jq '.[0] | {message: .commit.message, name: .commit.committer.name}'
# 响应
{
"message": "Fix accidentally quadratic behavior in _modify\n\nWe need to be careful to not grab an extra reference when mutating data\nstructures because that means we make extra copies. Doing that every\ntime in `_modify` is really painful, as that function implements `|=`\nand all modify-assign operators.\n\n`jv_setpath()` also grabs additional references, so this is not the only\nfix needed for the modify-assign operators to not be accidentally\nquadratic.\n\nWe have to use `LOADVN` in order to make this fix possible, so we should\nreally byte-code `_modify` rather than jq-code it. However, as a\nstop-gap to make this fix easier, I'm adding syntax for referring to a\n`$binding` such that you get `LOADVN` instead of `LOADV`.\n\nThis syntax is not meant to be used outside jq's internals! Therefore\nit is not documented. I promise to break it later, so don't use it!\n\nTBD, but later:\n\n - Optimize `_modify` for the case where `update` outputs more than one\n value.\n\n This is trivial: add a `setpath($p; null)` in the middle of `_modify`\n before calling `update`. But unfortunately the VM retains a\n reference to `value_at_path` for path expression checking, and fixing\n that will require more work.",
"name": "Nicolas Williams"
}
5、jq获取json数组中所有的指定字段
# 操作
curl 'https://api.github.com/repos/stedolan/jq/commits?per_page=5' | jq '.[] | {message: .commit.message, name: .commit.committer.name}'
# 响应
{
"message": "Fix accidentally quadratic behavior in _modify\n\nWe need to be careful to not grab an extra reference when mutating data\nstructures because that means we make extra copies. Doing that every\ntime in `_modify` is really painful, as that function implements `|=`\nand all modify-assign operators.\n\n`jv_setpath()` also grabs additional references, so this is not the only\nfix needed for the modify-assign operators to not be accidentally\nquadratic.\n\nWe have to use `LOADVN` in order to make this fix possible, so we should\nreally byte-code `_modify` rather than jq-code it. However, as a\nstop-gap to make this fix easier, I'm adding syntax for referring to a\n`$binding` such that you get `LOADVN` instead of `LOADV`.\n\nThis syntax is not meant to be used outside jq's internals! Therefore\nit is not documented. I promise to break it later, so don't use it!\n\nTBD, but later:\n\n - Optimize `_modify` for the case where `update` outputs more than one\n value.\n\n This is trivial: add a `setpath($p; null)` in the middle of `_modify`\n before calling `update`. But unfortunately the VM retains a\n reference to `value_at_path` for path expression checking, and fixing\n that will require more work.",
"name": "Nicolas Williams"
}
{
"message": "Fix accidentally quadratic behavior in setpath\n\nWe need to be careful to not grab an extra reference when mutating\ndata structures because that means we make extra copies. Doing that\nevery time in `jv_setpath()` is really painful, as that function is used\nin `_modify/2`, which is used in `|=` and all modify-assign operators.\n\n`_modify` also grabs additional references, so this is not the only fix\nneeded for the modify-assign operators to not be accidentally quadratic.",
"name": "Nicolas Williams"
}
{
"message": "Fix LOADV/LOADVN refcount printing",
"name": "Nicolas Williams"
}
{
"message": "Fix crash in LOADVN when stack grows\n\nThis `stack_push()` call in LOADVN invalidates `var`:\n\n jv* var = frame_local_var(jq, v, level);\n jv_free(stack_popn(jq));\n------>stack_push(jq, *var);\n *var = jv_null();\n ^^^^^^\n\nWe have to re-compute `var`:\n\n jv* var = frame_local_var(jq, v, level);\n jv_free(stack_popn(jq));\n stack_push(jq, *var);\n------>var = frame_local_var(jq, v, level);\n *var = jv_null();",
"name": "Nicolas Williams"
}
{
"message": "Appveyor: Get Appveyor building again",
"name": "Nicolas Williams"
}
6、jq获取json数组中所有的指定字段并存入数组
# 操作
curl 'https://api.github.com/repos/stedolan/jq/commits?per_page=5' | jq '[.[] | {message: .commit.message, name: .commit.committer.name}]'
# 响应
[
{
"message": "Fix accidentally quadratic behavior in _modify\n\nWe need to be careful to not grab an extra reference when mutating data\nstructures because that means we make extra copies. Doing that every\ntime in `_modify` is really painful, as that function implements `|=`\nand all modify-assign operators.\n\n`jv_setpath()` also grabs additional references, so this is not the only\nfix needed for the modify-assign operators to not be accidentally\nquadratic.\n\nWe have to use `LOADVN` in order to make this fix possible, so we should\nreally byte-code `_modify` rather than jq-code it. However, as a\nstop-gap to make this fix easier, I'm adding syntax for referring to a\n`$binding` such that you get `LOADVN` instead of `LOADV`.\n\nThis syntax is not meant to be used outside jq's internals! Therefore\nit is not documented. I promise to break it later, so don't use it!\n\nTBD, but later:\n\n - Optimize `_modify` for the case where `update` outputs more than one\n value.\n\n This is trivial: add a `setpath($p; null)` in the middle of `_modify`\n before calling `update`. But unfortunately the VM retains a\n reference to `value_at_path` for path expression checking, and fixing\n that will require more work.",
"name": "Nicolas Williams"
},
{
"message": "Fix accidentally quadratic behavior in setpath\n\nWe need to be careful to not grab an extra reference when mutating\ndata structures because that means we make extra copies. Doing that\nevery time in `jv_setpath()` is really painful, as that function is used\nin `_modify/2`, which is used in `|=` and all modify-assign operators.\n\n`_modify` also grabs additional references, so this is not the only fix\nneeded for the modify-assign operators to not be accidentally quadratic.",
"name": "Nicolas Williams"
},
{
"message": "Fix LOADV/LOADVN refcount printing",
"name": "Nicolas Williams"
},
{
"message": "Fix crash in LOADVN when stack grows\n\nThis `stack_push()` call in LOADVN invalidates `var`:\n\n jv* var = frame_local_var(jq, v, level);\n jv_free(stack_popn(jq));\n------>stack_push(jq, *var);\n *var = jv_null();\n ^^^^^^\n\nWe have to re-compute `var`:\n\n jv* var = frame_local_var(jq, v, level);\n jv_free(stack_popn(jq));\n stack_push(jq, *var);\n------>var = frame_local_var(jq, v, level);\n *var = jv_null();",
"name": "Nicolas Williams"
},
{
"message": "Appveyor: Get Appveyor building again",
"name": "Nicolas Williams"
}
]
7、jq高级用法
curl 'https://api.github.com/repos/stedolan/jq/commits?per_page=5' | jq '[.[] | {message: .commit.message, name: .commit.committer.name, parents: [.parents[].html_url]}]'
# 响应
[
{
"message": "Fix accidentally quadratic behavior in _modify\n\nWe need to be careful to not grab an extra reference when mutating data\nstructures because that means we make extra copies. Doing that every\ntime in `_modify` is really painful, as that function implements `|=`\nand all modify-assign operators.\n\n`jv_setpath()` also grabs additional references, so this is not the only\nfix needed for the modify-assign operators to not be accidentally\nquadratic.\n\nWe have to use `LOADVN` in order to make this fix possible, so we should\nreally byte-code `_modify` rather than jq-code it. However, as a\nstop-gap to make this fix easier, I'm adding syntax for referring to a\n`$binding` such that you get `LOADVN` instead of `LOADV`.\n\nThis syntax is not meant to be used outside jq's internals! Therefore\nit is not documented. I promise to break it later, so don't use it!\n\nTBD, but later:\n\n - Optimize `_modify` for the case where `update` outputs more than one\n value.\n\n This is trivial: add a `setpath($p; null)` in the middle of `_modify`\n before calling `update`. But unfortunately the VM retains a\n reference to `value_at_path` for path expression checking, and fixing\n that will require more work.",
"name": "Nicolas Williams",
"parents": [
"https://github.com/stedolan/jq/commit/0c3455d3290fa03da8c01c135dd7126a80ed28a8"
]
},
{
"message": "Fix accidentally quadratic behavior in setpath\n\nWe need to be careful to not grab an extra reference when mutating\ndata structures because that means we make extra copies. Doing that\nevery time in `jv_setpath()` is really painful, as that function is used\nin `_modify/2`, which is used in `|=` and all modify-assign operators.\n\n`_modify` also grabs additional references, so this is not the only fix\nneeded for the modify-assign operators to not be accidentally quadratic.",
"name": "Nicolas Williams",
"parents": [
"https://github.com/stedolan/jq/commit/1a1804afcb88cdc3f1f0e74e83385146b55ae205"
]
},
{
"message": "Fix LOADV/LOADVN refcount printing",
"name": "Nicolas Williams",
"parents": [
"https://github.com/stedolan/jq/commit/582717a7b4af6ce0e231b9aee090107235ef2d0f"
]
},
{
"message": "Fix crash in LOADVN when stack grows\n\nThis `stack_push()` call in LOADVN invalidates `var`:\n\n jv* var = frame_local_var(jq, v, level);\n jv_free(stack_popn(jq));\n------>stack_push(jq, *var);\n *var = jv_null();\n ^^^^^^\n\nWe have to re-compute `var`:\n\n jv* var = frame_local_var(jq, v, level);\n jv_free(stack_popn(jq));\n stack_push(jq, *var);\n------>var = frame_local_var(jq, v, level);\n *var = jv_null();",
"name": "Nicolas Williams",
"parents": [
"https://github.com/stedolan/jq/commit/07dc653ae151a8320646a1c955839fb88d4a5546"
]
},
{
"message": "Appveyor: Get Appveyor building again",
"name": "Nicolas Williams",
"parents": [
"https://github.com/stedolan/jq/commit/d79fe7fd582fe0dfdb253445e8ccd671d6fdf8b6"
]
}
]
网友评论