FryingFinn has asked for the wisdom of the Perl Monks concerning the following question:
I just started w JSON. & I'm having a problem reading a simple? file.
I keep getting the error
"garbage after JSON object, at character offset 255 (before " "_id" : 1, "name" :...") at ./rd_students.pl line 12."
The json test file is ..
{ "_id" : 0, "name" : "Betty Boop", "subjects" : [ { "type" : "optional", "subject" : "Voice"}, { "type" : "required", "subject" : "Math" }, { "type" : "required", "subject" : "English" } ] } { "_id" : 1, "name" : "Donald Duck", "subjects" : [ { "type" : "optional", "subject" : "Accounting" }, { "type" : "required", "subject" : "Math" }, { "type" : "required", "subject" : "English" } ] }
The perl script..
#!/usr/bin/env perl use JSON; use Data::Dumper; use Perl6::Slurp; my $file = 'test.json'; my $json = slurp $file; $text = decode_json($json); print Dumper($text);
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: reading JSON
by neilwatson (Priest) on Jun 16, 2015 at 18:40 UTC | |
|
Re: reading JSON
by jeffa (Bishop) on Jun 16, 2015 at 18:41 UTC | |
by marinersk (Priest) on Jun 16, 2015 at 19:28 UTC |