omegaweaponZ has asked for the wisdom of the Perl Monks concerning the following question:
etc.... (there is a lot more, ignore malformed JSON!) So instead of something that has an all encompassing array reference such as{ "1": {"subject1": "value", "subject2": [{"subject3": "value", "subject +4": "value"}], "subject5": "value", "subject6": value, "subject7": "v +alue"}, "2": {"subject1": "value", "subject2": [{"subject3": "value", "subject +4": "value"}], "subject5": "value", "subject6": value, "subject7": "v +alue"}, "3": {"subject1": "value", "subject2": [{"subject3": "value", "subject +4": "value"}], "subject5": "value", "subject6": value, "subject7": "v +alue"},
Which would be easy where I can identify each subject's value by a format similar to the one below, it is just separated essentially by unique numbers line by line from {} which are not detecting the array. My older code had said something along the lines of:DATA [ "1": {"subject1": "value"}, "2": {"subject1": "value"} ]
Doing this produces "Not an Array Reference". If I was to use "subject2" as oppsed to 1 from $json-> it does not error out, yet does not show subject 3, subject 4, etc's value.my $jsonoutput = "Above raw JSON format..."; my $json = new JSON; my $jsontext = $json->allow_nonref->utf8->relaxed->escape_slash->l +oose->allow_singlequote->allow_barekey->decode("$jsonoutput"); foreach my $stuff(@{$json->{1}}){ my %hash = (); $hash{subject1} = $stuff->{subject1}; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Extract JSON data
by roboticus (Chancellor) on May 18, 2013 at 21:07 UTC | |
by Random_Walk (Prior) on May 19, 2013 at 11:00 UTC | |
by omegaweaponZ (Beadle) on May 21, 2013 at 13:59 UTC | |
by omegaweaponZ (Beadle) on May 22, 2013 at 20:28 UTC | |
|
Re: Extract JSON data
by LanX (Saint) on May 18, 2013 at 21:01 UTC | |
|
Re: Extract JSON data
by hdb (Monsignor) on May 18, 2013 at 21:03 UTC |