anautismobserver has asked for the wisdom of the Perl Monks concerning the following question:
EDITED to add: this has been solved. Thanks so much.
I'm a perl novice who wants to learn just enough perl to get by without putting much effort into it.
Please tell me how to read the JSON object returned by
obtained fromhttp://web.archive.org/cdx/search/cdx?url=archive.org&output=json&limi +t=3
https://github.com/internetarchive/wayback/tree/master/wayback-cdx-ser +ver#output-format-json
CLARIFICATION ADDED: Below is an example json object. I want to assign a variable $first_timestamp to the first timestamp (19970126045828).
[["urlkey","timestamp","original","mimetype","statuscode","digest","le +ngth"], ["org,archive)/", "19970126045828", "http://www.archive.org:80/", "te +xt/html", "200", "Q4YULN754FHV2U6Q5JUT6Q2P57WEWNNY", "1415"], ["org,archive)/", "19971011050034", "http://www.archive.org:80/", "te +xt/html", "200", "XAHDNHZ5P3GSSSNJ3DMEOJF7BMCCPZR3", "1402"], ["org,archive)/", "19971211122953", "http://www.archive.org:80/", "te +xt/html", "200", "XAHDNHZ5P3GSSSNJ3DMEOJF7BMCCPZR3", "1405"]]
How do I do that?
Context:
I currently have the following working code:
use strict; use warnings; use Mojo::UserAgent; use LWP::UserAgent; use HTTP::Request::Common qw(GET); my $outputFilename = "test_output.txt"; my $fh_data; my $name; open( $fh_data, '>', $outputFilename ) or die "Could not open file '$outputFilename' $!"; my $url = "https://public-api.wordpress.com/rest/v1/read/feed/?url=anautismobser +ver.wordpress.com"; my $ua = Mojo::UserAgent->new; my $json = $ua->get($url)->res->json; for my $feedurl ( @{ $json->{feeds} } ) { if ( $feedurl->{meta}{links}{site} ) { my $siteurl2 = $feedurl->{meta}{links}{site}; my $ua2 = Mojo::UserAgent->new; my $json3 = $ua2->get($siteurl2)->res->json; $name = $json3->{name}; print $fh_data "$name"; } } close $fh_data;
I want to modify the code to read the JSON object returned if I set
my $url = http://web.archive.org/cdx/search/cdx?url=archive.org&output +=json&limit=3
and I want to write the timestamps into a text file.
Thank you.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: reading a JSON object
by Corion (Patriarch) on May 08, 2022 at 19:22 UTC | |
by anautismobserver (Sexton) on May 09, 2022 at 01:33 UTC | |
by marto (Cardinal) on May 09, 2022 at 08:39 UTC | |
by anautismobserver (Sexton) on May 08, 2022 at 20:06 UTC | |
|
Re: reading a JSON object
by AnomalousMonk (Archbishop) on May 09, 2022 at 04:51 UTC | |
by anautismobserver (Sexton) on May 09, 2022 at 18:01 UTC | |
by AnomalousMonk (Archbishop) on May 09, 2022 at 18:39 UTC | |
by anautismobserver (Sexton) on May 09, 2022 at 20:25 UTC | |
by AnomalousMonk (Archbishop) on May 09, 2022 at 20:47 UTC | |
| |
by anautismobserver (Sexton) on May 09, 2022 at 22:34 UTC | |
by AnomalousMonk (Archbishop) on May 09, 2022 at 23:39 UTC | |
| |
by anautismobserver (Sexton) on May 15, 2022 at 21:48 UTC | |
by choroba (Cardinal) on May 15, 2022 at 22:17 UTC | |
by Corion (Patriarch) on May 16, 2022 at 07:50 UTC |