Posted: . At: 5:29 AM. This was 4 months ago. Post ID: 18957
Page permalink. WordPress uses cookies, or tiny pieces of information stored on your computer, to verify who you are. There are cookies for logged in users and for commenters.
These cookies expire two weeks after they are set.


How to read a JSON file using jq on the Internet.


Reading a JSON file from a website is not too hard. I have used this to read a TV station listing from a website.

(jcartwright@localhost) 192.168.1.5 ~  $ curl -s https://i.mjh.nz/au/all/tv.json | jq -r '.[] | .name,.mjh_master' | uniq | tr '' '\t'
Xtreme Adventure
https://i.mjh.nz/10-action-and-adventure.m3u8
America's Next Top Model
https://i.mjh.nz/10-americas-next-top-model.m3u8
Becker
https://i.mjh.nz/10-becker.m3u8
Beverly Hills 90210
https://i.mjh.nz/10-beverlyhills90210.m3u8
Bold and The Beautiful Classics
https://i.mjh.nz/10-bold-and-the-beautiful-classics.m3u8
Bondi Rescue
https://i.mjh.nz/10-bondi-rescue.m3u8
Baywatch
https://i.mjh.nz/10-buzzrbaywatch.m3u8
Diagnosis Murder
https://i.mjh.nz/10-diagnosismurder.m3u8
Dynasty
https://i.mjh.nz/10-dynasty.m3u8
48 Hours
https://i.mjh.nz/10-forty-eight-hours.m3u8
Gecko TV
https://i.mjh.nz/10-geckotv.m3u8
Gunsmoke
https://i.mjh.nz/10-gunsmoke.m3u8
Happy Days
https://i.mjh.nz/10-happy_days.m3u8
Haunt TV
https://i.mjh.nz/10-haunt-tv.m3u8
Hawaii Five-O
https://i.mjh.nz/10-hawaii_five_o.m3u8
I Love Lucy
https://i.mjh.nz/10-i_love_lucy.m3u8
Judge Judy
https://i.mjh.nz/10-judge-judy.m3u8
MasterChef
https://i.mjh.nz/10-masterchef.m3u8
Matlock
https://i.mjh.nz/10-matlock.m3u8

Read the file from the website like this.

curl -s https://i.mjh.nz/au/all/tv.json

Then the JSON may be parsed easily using jq.

jq -r '.[] | .name,.mjh_master' | uniq | tr '' '\t'

Here is another example.

(jcartwright@localhost) 192.168.1.5 ~  $ curl -s https://i.mjh.nz/au/Sydney/radio.json | jq -r '.[] | .name,.logo,.mjh_master' | uniq | tr '' '\t'
2GB
https://i.mjh.nz/.images/radio-2gb.png
https://i.mjh.nz/radio-2gb
Chemist Warehouse Remix
https://i.iheart.com/v3/re/new_assets/5b862f497f66f2e1e526ba23
https://i.mjh.nz/radio-ih-6178.aac
CADA
https://i.iheart.com/v3/re/new_assets/623faa90fb788a23d0b662b2
https://i.mjh.nz/radio-ih-6179.aac
KIIS 1065
https://i.iheart.com/v3/re/assets/images/fa2db663-cc83-4148-8312-886ce94029ae.png
https://i.mjh.nz/radio-ih-6185.aac
101.7 WSFM
https://i.iheart.com/v3/re/assets/images/6186.png
https://i.mjh.nz/radio-ih-6186.aac
FBi Radio
https://i.iheart.com/v3/re/new_assets/5d2697e31008b9c838483bdb
https://i.mjh.nz/radio-ih-6311
Fine Music Sydney
https://i.iheart.com/v3/re/new_assets/615e975c61f05b7e6ec34368
https://i.mjh.nz/radio-ih-6312.aacp
Hope 103.2
https://i.iheart.com/v3/re/new_assets/5d23ed28db1e1347a068f5af
https://i.mjh.nz/radio-ih-6314
Inspire Digital
https://i.iheart.com/v3/re/new_assets/5d23ee2ddb1e1347a068f5b1
https://i.mjh.nz/radio-ih-6315
2SER
https://i.iheart.com/v3/re/new_assets/5d721ff869be7ce36cfaee3f
https://i.mjh.nz/radio-ih-6324
The Bounce
https://i.iheart.com/v3/re/new_assets/5e5f0594028e5dab486781c6
https://i.mjh.nz/radio-ih-6327.aac
Energy Groove
https://i.iheart.com/v3/re/new_assets/5e2faa40ff9c5ccb5900110a
https://i.mjh.nz/radio-ih-6329
Elf Radio
https://i.iheart.com/v3/re/assets.streams/65829abbdd36e28e7d7fefa2
https://i.mjh.nz/radio-ih-6440.aac

And you may read from a WordPress website as well, this is a good way to list all recent posts.

(jcartwright@localhost) 192.168.1.5 ~  $ curl -s https://www.news.com.au/wp-json/wp/v2/posts/ | jq -r '.[] | .title,.link,.excerpt,.modified'
{
  "rendered": "Most popular articles for newscomau-article-all-24hours"
}
https://www.news.com.au/news/most-popular-articles-for-newscomauarticleall24hours/collection/387f107c03a9a43c8bb456a373b4fdf0
{
  "rendered": "",
  "protected": false
}
2023-12-27T05:00:54
{
  "rendered": "US holiday sales miss expectations -Mastercard report"
}
https://www.news.com.au/national/us-holiday-sales-miss-expectations-mastercard-report/video/c4c32eb9e65f458891982050fa31a8cb
{
  "rendered": "",
  "protected": false
}
2023-12-27T05:01:58

Another example.

(jcartwright@localhost) 192.168.1.5 ~  $ curl -s https://www.securitronlinux.com/wp-json/wp/v2/posts/ | jq -r '.[] | .title,.link,.excerpt,.modified'
{
  "rendered": "True Stalker mod has been released!"
}
True Stalker mod has been released!
{ "rendered": "<p>True Stalker Call of Pripyat mod has been released. Very exciting.</p>\n", "protected": false } 2023-12-26T06:58:39 { "rendered": "How to get video information from YouTube in JSON format and parse it." }
How to get video information from YouTube in JSON format and parse it.
{ "rendered": "<p>How to list information from a YouTube video in the terminal on Linux.</p>\n", "protected": false } 2023-12-22T10:14:18 { "rendered": "Installing and using Linux Mint Edge is a lot of fun." }
Installing and using Linux Mint Edge is a lot of fun.
{ "rendered": "<p>Installing and updating Linux Mint is a lot of fun. This is a very good distro now.</p>\n", "protected": false } 2023-12-18T14:13:21 { "rendered": "Arma Reforger PDF map. See all the locations on the Everon map." }
Arma Reforger PDF map. See all the locations on the Everon map.
{ "rendered": "<p>The Arma Reforger PDF map. A good way to learn the layout of Everon.</p>\n", "protected": false } 2023-12-20T09:31:36

This is a neat trick, this is very useful to read a list of all recent posts on a WordPress website and should be a very useful technique for getting data from any website that uses JSON.


Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.