0

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?

1 Answer 1

2

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: [...].

Sign up to request clarification or add additional context in comments.

1 Comment

@user2201935 — The reduction in content makes the code a better example of a reduced test case. The loss of indenting makes it worse. The problem you actually have is still the same, and this answer still explains what you need to do to fix it.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.