user2201935
user2201935

Reputation: 396

JSON Data output

Below is the Perl code having JSON data:

use Data::Dumper;
use JSON;

my $var = '{

    "episode1": {
      "title":"Cartman Gets an Anal Probe",
      "id":"103511",
      "airdate":"08.13.97",
      "episodenumber":"101",
      "available":"true",
      "when":"08.13.97"
    }
  },
  {
    "episode2": {
      "title":"Weight Gain 4000",
      "id":"103516",
      "airdate":"08.20.97",
      "episodenumber":"102",
      "available":"true",
      "when":"08.20.97"
    }
}';

my $resp = JSON::jsonToObj( $var );

print Dumper ($resp);

The output is:

$VAR1 = {
  'episode1' => {
    'when' => '08.13.97',
    'episodenumber' => '101',
    'airdate' => '08.13.97',
    'title' => 'Cartman Gets an Anal Probe',
    'id' => '103511',
    'available' => 'true'
  }
};

I am dumping a JSON data but only episode1 is dumped in the output. But, I want both episode1 and episode2 to be displayed when I dump. How to do it?

Upvotes: 0

Views: 62

Answers (1)

Quentin
Quentin

Reputation: 944568

Write valid JSON.

From JSON Lint

Parse error on line 14:
...: "08.13.97"    }},{    "episode2": 
---------------------^
Expecting 'EOF'

If you want an array of objects, you need an array in the data: [...].

Upvotes: 2

Related Questions