in reply to Re^2: reading a JSON object
in thread reading a JSON object
I'm confused.
my $json_string = $ua->get($url)->res->json;
Is $json_string in fact a string, or is it a decoded JSON object as shown in the example here, i.e., a reference to an array of arrays (in that particular example)? Your use of the $json_string->[0][0] syntax suggests the latter.
If $json_string is in fact a ref. to an AoA, you might do something like this:
(I used different formatting just to try to make things fit better and to clearly delineate the strings. Sorry about the wraparound.)Win8 Strawberry 5.30.3.1 (64) Mon 05/09/2022 14:30:45 C:\@Work\Perl\monks >perl use strict; use warnings; use JSON; use Data::Dump qw(dd); my $json_string = <<'EOJ'; [["urlkey","timestamp","original","mimetype","statuscode","digest","le +ngth"], ["org,archive)/", "19970126045828", "http://www.archive.org:80/", "text/html", "200", "Q4YULN754FHV2U6Q5JUT6Q2P57WEWNNY", "1415"], ["org,archive)/", "19971011050034", "http://www.archive.org:80/", "text/html", "200", "XAHDNHZ5P3GSSSNJ3DMEOJF7BMCCPZR3", "1402"], ["org,archive)/", "19971211122953", "http://www.archive.org:80/", "text/html", "200", "XAHDNHZ5P3GSSSNJ3DMEOJF7BMCCPZR3", "1405"]] EOJ my $ar_decoded_json = decode_json $json_string; # dd $ar_decoded_json; # for debug for my $ar_jentry (@$ar_decoded_json) { # handle each decoded JSON en +try printf "\n'%s' '%s' '%s' '%s' '%s' '%s' '%s'", @$ar_jentry; } ^Z 'urlkey' 'timestamp' 'original' 'mimetype' 'statuscode' 'digest' 'leng +th' 'org,archive)/' '19970126045828' 'http://www.archive.org:80/' 'text/ht +ml' '200' 'Q4YULN754FHV2U6Q5JU T6Q2P57WEWNNY' '1415' 'org,archive)/' '19971011050034' 'http://www.archive.org:80/' 'text/ht +ml' '200' 'XAHDNHZ5P3GSSSNJ3DM EOJF7BMCCPZR3' '1402' 'org,archive)/' '19971211122953' 'http://www.archive.org:80/' 'text/ht +ml' '200' 'XAHDNHZ5P3GSSSNJ3DM EOJF7BMCCPZR3' '1405'
Give a man a fish: <%-{-{-{-<
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^4: reading a JSON object
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 | |
|
Re^4: reading a JSON object
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 anautismobserver (Sexton) on May 11, 2022 at 19:45 UTC | |
| |
by Discipulus (Canon) on May 11, 2022 at 11:12 UTC | |
by AnomalousMonk (Archbishop) on May 11, 2022 at 15:56 UTC |