in reply to Re: reading a JSON object
in thread reading a JSON object
Thanks. That's exactly the information I needed.
EDITED to add: the question below has been answered. Thanks so much.
Now I have another ignorant question. Below is my current working code. How do I get the size of the JSON object $json_string, and how do I loop over the first index?
use strict; use warnings; use Mojo::UserAgent; use LWP::UserAgent; use HTTP::Request::Common qw(GET); # use JSON; use Data::Dump qw(dd); my $outputFilename = "test_output.txt"; my $fh_data; my $urlkey_result; my $timestamp_result; my $original_result; my $mimetype_result; my $statuscode_result; my $digest_result; my $length_result; open( $fh_data, '>', $outputFilename ) or die "Could not open file '$outputFilename' $!"; my $url = "http://web.archive.org/cdx/search/cdx?url=anautismobserver.wordpress. +com&output=json"; # &limit=3 my $ua = Mojo::UserAgent->new; my $json_string = $ua->get($url)->res->json; # dd $json_string; # for debug $urlkey_result = $json_string->[0][0]; $timestamp_result = $json_string->[0][1]; $original_result = $json_string->[0][2]; $mimetype_result = $json_string->[0][3]; $statuscode_result = $json_string->[0][4]; $digest_result = $json_string->[0][5]; $length_result = $json_string->[0][6]; print $fh_data "\n$urlkey_result\t$timestamp_result\t$original_result\ +t$mimetype_result\t$statuscode_result\t$digest_result\t$length_result +"; $urlkey_result = $json_string->[1][0]; $timestamp_result = $json_string->[1][1]; $original_result = $json_string->[1][2]; $mimetype_result = $json_string->[1][3]; $statuscode_result = $json_string->[1][4]; $digest_result = $json_string->[1][5]; $length_result = $json_string->[1][6]; print $fh_data "\n$urlkey_result\t$timestamp_result\t$original_result\ +t$mimetype_result\t$statuscode_result\t$digest_result\t$length_result +"; $urlkey_result = $json_string->[2][0]; $timestamp_result = $json_string->[2][1]; $original_result = $json_string->[2][2]; $mimetype_result = $json_string->[2][3]; $statuscode_result = $json_string->[2][4]; $digest_result = $json_string->[2][5]; $length_result = $json_string->[2][6]; print $fh_data "\n$urlkey_result\t$timestamp_result\t$original_result\ +t$mimetype_result\t$statuscode_result\t$digest_result\t$length_result +"; $urlkey_result = $json_string->[3][0]; $timestamp_result = $json_string->[3][1]; $original_result = $json_string->[3][2]; $mimetype_result = $json_string->[3][3]; $statuscode_result = $json_string->[3][4]; $digest_result = $json_string->[3][5]; $length_result = $json_string->[3][6]; print $fh_data "\n$urlkey_result\t$timestamp_result\t$original_result\ +t$mimetype_result\t$statuscode_result\t$digest_result\t$length_result +"; close $fh_data;
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^3: reading a JSON object
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 21:39 UTC | |
by anautismobserver (Sexton) on May 09, 2022 at 21:58 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 10, 2022 at 17:46 UTC | |
by anautismobserver (Sexton) on May 11, 2022 at 10:45 UTC | |
by hippo (Archbishop) on May 11, 2022 at 11:01 UTC | |
| |
by Discipulus (Canon) on May 11, 2022 at 11:12 UTC | |
by AnomalousMonk (Archbishop) on May 11, 2022 at 15:56 UTC |