in reply to Extract JSON data
I'd suggest using JSON to parse out JSON items. Be aware, however, that the data you show in your example is not valid JSON. Be sure to arrange with the provider of the so-called JSON to have them correct it. The bits I see wrong are:
I don't know whether the commas are a problem or not, but the missing curly braces and missing quotes are problematic. Once you fix the data, the JSON package makes parsing trivial:
$ cat t.pl use strict; use warnings; use Data::Dumper; use JSON; my $text; { local $/;$text= <DATA> }; my $junk = decode_json($text); print Dumper($junk); __DATA__ { "1": { "subject1": "value", "subject2": [ { "subject3": "value", "su +bject4": "value" } ], "subject5": "value", "subject6": "value", "subj +ect7": "value" } } $ perl t.pl $VAR1 = { '1' => { 'subject7' => 'value', 'subject2' => [ { 'subject4' => 'value', 'subject3' => 'value' } ], 'subject5' => 'value', 'subject1' => 'value', 'subject6' => 'value' } };
...roboticus
When your only tool is a hammer, all problems look like your thumb.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Extract JSON data
by Random_Walk (Prior) on May 19, 2013 at 11:00 UTC | |
|
Re^2: Extract JSON data
by omegaweaponZ (Beadle) on May 21, 2013 at 13:59 UTC | |
by omegaweaponZ (Beadle) on May 22, 2013 at 20:28 UTC |