in reply to Perplexing JSON decoding issue.

@choroba, it is the Dumper from Data::Dumper; I use it often when working with Json to see the entire response formatted nicely. Helps a lot to see what variables and arrays are listed.

@haukex, that worked to fix it perfectly. Thanks for that. I'd have torn my hair out all day trying to figure out why it wasn't working when every other time I used Json it worked. I also noticed that it worked as $apiJson[0]->[0]->{'id'}; Not entirely sure what makes that different but I am using the way you wrote it as it is shorter by a few characters for the same result. My terminal now shows:

msgId: 233638292636041218 <MiyakoProductions> test3

Replies are listed 'Best First'.
Re^2: Perplexing JSON decoding issue.
by haukex (Archbishop) on Oct 06, 2016 at 17:58 UTC

    Hi Miyako,

    I also noticed that it worked as $apiJson[0]->[0]->{'id'}; Not entirely sure what makes that different

    Compare these two:

    my @apiJson = decode_json( $apiContent ); my $msgID = $apiJson[0]->[0]{id}; # or # my $apiJson = decode_json( $apiContent ); my $msgID = $apiJson->[0]{id};

    In the first, you're taking the return value of decode_json, which I believe is just a single value, an arrayref or hashref, storing it in an array @apiJson which now just has a single element, and accessing that element with $apiJson[0]. In the second version, you're taking that single return value and storing it in the scalar $apiJson directly. (As far as I can tell decode_json behaves the same in list and array context.)

    Hope this helps,
    -- Hauke D