I have spent the last 4 hours combing all over the internet for advice and ideas on how to capture a string of interest so that I can pipe it into a variable inside of a bash script for use later in the script.
I have run out of all ideas on how to do this.
I simply want to use jq to get the following string as it’s output when using the following json file as the file input.
I need to capture the string
"browser_download_url": "https://github.com/ArtifexSoftware/ghostpdl-downloads/releases/download/gs10011/ghostpdl-10.01.1.tar.xz"
specifically the value part
https://github.com/ArtifexSoftware/ghostpdl-downloads/releases/download/gs10011/ghostpdl-10.01.1.tar.xz
For those who agree with me that the code I have posted below is rediculous in size please see the following GitHub link that will take you right to the line I want to capture.
The only successes I have had besides no output being found are a few commands like
jq '.[].url' github.json
jq '.[3].url' github.json
jq '.[9][]' github.json
As is obvious I am stupefied and really need some of you guys advice and good help that comes with posting here.
ANY ideas would make my whole day!
[
{
"url": "https://api.github.com/repos/ArtifexSoftware/ghostpdl-downloads/releases/96992569",
"assets_url": "https://api.github.com/repos/ArtifexSoftware/ghostpdl-downloads/releases/96992569/assets",
"upload_url": "https://uploads.github.com/repos/ArtifexSoftware/ghostpdl-downloads/releases/96992569/assets{?name,label}",
"html_url": "https://github.com/ArtifexSoftware/ghostpdl-downloads/releases/tag/gs10011",
"id": 96992569,
"author": {
"login": "chris-liddell",
"id": 11627080,
"node_id": "MDQ6VXNlcjExNjI3MDgw",
"avatar_url": "https://avatars.githubusercontent.com/u/11627080?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/chris-liddell",
"html_url": "https://github.com/chris-liddell",
"followers_url": "https://api.github.com/users/chris-liddell/followers",
"following_url": "https://api.github.com/users/chris-liddell/following{/other_user}",
"gists_url": "https://api.github.com/users/chris-liddell/gists{/gist_id}",
"starred_url": "https://api.github.com/users/chris-liddell/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/chris-liddell/subscriptions",
"organizations_url": "https://api.github.com/users/chris-liddell/orgs",
"repos_url": "https://api.github.com/users/chris-liddell/repos",
"events_url": "https://api.github.com/users/chris-liddell/events{/privacy}",
"received_events_url": "https://api.github.com/users/chris-liddell/received_events",
"type": "User",
"site_admin": false
},
"node_id": "RE_kwDOAwH6wM4Fx_05",
"tag_name": "gs10011",
"target_commitish": "master",
"name": "Ghostscript/GhostPDL 10.01.1",
"draft": false,
"prerelease": false,
"created_at": "2023-03-27T08:44:15Z",
"published_at": "2023-03-27T10:02:24Z",
"assets": [
{
"url": "https://api.github.com/repos/ArtifexSoftware/ghostpdl-downloads/releases/assets/101122360",
"id": 101122360,
"node_id": "RA_kwDOAwH6wM4GBwE4",
"name": "ghostpcl-10.01.1-win32.zip",
"label": null,
"uploader": {
"login": "chris-liddell",
"id": 11627080,
"node_id": "MDQ6VXNlcjExNjI3MDgw",
"avatar_url": "https://avatars.githubusercontent.com/u/11627080?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/chris-liddell",
"html_url": "https://github.com/chris-liddell",
"followers_url": "https://api.github.com/users/chris-liddell/followers",
"following_url": "https://api.github.com/users/chris-liddell/following{/other_user}",
"gists_url": "https://api.github.com/users/chris-liddell/gists{/gist_id}",
"starred_url": "https://api.github.com/users/chris-liddell/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/chris-liddell/subscriptions",
"organizations_url": "https://api.github.com/users/chris-liddell/orgs",
"repos_url": "https://api.github.com/users/chris-liddell/repos",
"events_url": "https://api.github.com/users/chris-liddell/events{/privacy}",
"received_events_url": "https://api.github.com/users/chris-liddell/received_events",
"type": "User",
"site_admin": false
},
"content_type": "application/zip",
"state": "uploaded",
"size": 10126052,
"download_count": 1081,
"created_at": "2023-03-27T08:51:12Z",
"updated_at": "2023-03-27T08:51:15Z",
"browser_download_url": "https://github.com/ArtifexSoftware/ghostpdl-downloads/releases/download/gs10011/ghostpcl-10.01.1-win32.zip"
},
{
"url": "https://api.github.com/repos/ArtifexSoftware/ghostpdl-downloads/releases/assets/101122363",
"id": 101122363,
"node_id": "RA_kwDOAwH6wM4GBwE7",
"name": "ghostpcl-10.01.1-win64.zip",
"label": null,
"uploader": {
"login": "chris-liddell",
"id": 11627080,
"node_id": "MDQ6VXNlcjExNjI3MDgw",
"avatar_url": "https://avatars.githubusercontent.com/u/11627080?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/chris-liddell",
"html_url": "https://github.com/chris-liddell",
"followers_url": "https://api.github.com/users/chris-liddell/followers",
"following_url": "https://api.github.com/users/chris-liddell/following{/other_user}",
"gists_url": "https://api.github.com/users/chris-liddell/gists{/gist_id}",
"starred_url": "https://api.github.com/users/chris-liddell/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/chris-liddell/subscriptions",
"organizations_url": "https://api.github.com/users/chris-liddell/orgs",
"repos_url": "https://api.github.com/users/chris-liddell/repos",
"events_url": "https://api.github.com/users/chris-liddell/events{/privacy}",
"received_events_url": "https://api.github.com/users/chris-liddell/received_events",
"type": "User",
"site_admin": false
},
"content_type": "application/zip",
"state": "uploaded",
"size": 10654174,
"download_count": 2190,
"created_at": "2023-03-27T08:51:15Z",
"updated_at": "2023-03-27T08:51:18Z",
"browser_download_url": "https://github.com/ArtifexSoftware/ghostpdl-downloads/releases/download/gs10011/ghostpcl-10.01.1-win64.zip"
},
{
"url": "https://api.github.com/repos/ArtifexSoftware/ghostpdl-downloads/releases/assets/101122291",
"id": 101122291,
"node_id": "RA_kwDOAwH6wM4GBwDz",
"name": "ghostpdl-10.01.1.tar.gz",
"label": null,
"uploader": {
"login": "chris-liddell",
"id": 11627080,
"node_id": "MDQ6VXNlcjExNjI3MDgw",
"avatar_url": "https://avatars.githubusercontent.com/u/11627080?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/chris-liddell",
"html_url": "https://github.com/chris-liddell",
"followers_url": "https://api.github.com/users/chris-liddell/followers",
"following_url": "https://api.github.com/users/chris-liddell/following{/other_user}",
"gists_url": "https://api.github.com/users/chris-liddell/gists{/gist_id}",
"starred_url": "https://api.github.com/users/chris-liddell/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/chris-liddell/subscriptions",
"organizations_url": "https://api.github.com/users/chris-liddell/orgs",
"repos_url": "https://api.github.com/users/chris-liddell/repos",
"events_url": "https://api.github.com/users/chris-liddell/events{/privacy}",
"received_events_url": "https://api.github.com/users/chris-liddell/received_events",
"type": "User",
"site_admin": false
},
"content_type": "application/gzip",
"state": "uploaded",
"size": 96849416,
"download_count": 2624,
"created_at": "2023-03-27T08:50:15Z",
"updated_at": "2023-03-27T08:50:32Z",
"browser_download_url": "https://github.com/ArtifexSoftware/ghostpdl-downloads/releases/download/gs10011/ghostpdl-10.01.1.tar.gz"
},
{
"url": "https://api.github.com/repos/ArtifexSoftware/ghostpdl-downloads/releases/assets/101122309",
"id": 101122309,
"node_id": "RA_kwDOAwH6wM4GBwEF",
"name": "ghostpdl-10.01.1.tar.xz",
"label": null,
"uploader": {
"login": "chris-liddell",
"id": 11627080,
"node_id": "MDQ6VXNlcjExNjI3MDgw",
"avatar_url": "https://avatars.githubusercontent.com/u/11627080?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/chris-liddell",
"html_url": "https://github.com/chris-liddell",
"followers_url": "https://api.github.com/users/chris-liddell/followers",
"following_url": "https://api.github.com/users/chris-liddell/following{/other_user}",
"gists_url": "https://api.github.com/users/chris-liddell/gists{/gist_id}",
"starred_url": "https://api.github.com/users/chris-liddell/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/chris-liddell/subscriptions",
"organizations_url": "https://api.github.com/users/chris-liddell/orgs",
"repos_url": "https://api.github.com/users/chris-liddell/repos",
"events_url": "https://api.github.com/users/chris-liddell/events{/privacy}",
"received_events_url": "https://api.github.com/users/chris-liddell/received_events",
"type": "User",
"site_admin": false
},
"content_type": "application/x-xz",
"state": "uploaded",
"size": 73020984,
"download_count": 7698,
"created_at": "2023-03-27T08:50:32Z",
"updated_at": "2023-03-27T08:50:49Z",
"browser_download_url": "https://github.com/ArtifexSoftware/ghostpdl-downloads/releases/download/gs10011/ghostpdl-10.01.1.tar.xz"
}
],
"tarball_url": "https://api.github.com/repos/ArtifexSoftware/ghostpdl-downloads/tarball/gs928rc3",
"zipball_url": "https://api.github.com/repos/ArtifexSoftware/ghostpdl-downloads/zipball/gs928rc3",
"body": ""
}
]
2
Answers
The desired string is the last produced by:
so in the absence of more detailed requirements, I’ll go with wrapping this in last():
Here’s another way to do it using
tostream
.Try it on jqplay.org.