in reply to Help with JSON Module

G'day James,

I see ++philiprbrenan has solved the Useless use of a constant ... problem.

For the malformed JSON ... problem, it might be better to look at your input JSON rather than what's being output with the error message. Try:

my $code = $tesco->product_search({ searchtext => $pn, extendedinfo => + 'N' }); print $code, "\n"; exit;

You might be able to see the problem by inspection; if not, try running it through the validator you mentioned earlier.

[Aside: I'll just point out that chomp is a safer version of chop. Of course, you might have a perfectly valid reason for choosing chop.]

-- Ken

Replies are listed 'Best First'.
Re^2: Help with JSON Module
by foggy3657 (Novice) on Sep 08, 2012 at 08:26 UTC

    Thank you for trying to help.

    All your code returns is HASH(0x9fbf738)

    I have tried the validator and it definitely returns Valid.

    I can't help thinking that my JSON decode syntax is incorrect somehow.

    Best wishes - James

      And there's your problem identified.

      JSON's decode method has this syntax:

      $perl_scalar = $json->decode($json_text)

      but you're invoking it as:

      $perl_scalar = $json->decode($hash_reference)

      Use Data::Dumper to determine what data the hash reference points to. Perhaps your JSON string is in there somewhere.

      -- Ken

        Thank you. However with the following code:

        #!/usr/bin/perl use warnings; use strict; use WebService::Tesco::API; use JSON; use Data::Dumper my $tesco = WebService::Tesco::API->new( app_key => 'xxxxx', developer +_key => 'xxxx', debug => 1, ); my $result = $tesco->login({ email => 'xxxxx@yahoo.co.uk', password => + 'xxxxx', }); print "Scan Item...."; my $pn = <>; #Scan Bar Code chop ($pn); # +remove %OA from end of scan code my $code = $tesco->product_search({ searchtext => $pn, extendedinfo => + 'N' }); print Dumper ($code);

        All I get is:

        "WebService::Tesco::API=HASH(0xf66940)" is not exported by the Data::D +umper module Can't continue after import errors at tesco_json_dumper.pl line 9. BEGIN failed--compilation aborted at tesco_json_dumper.pl line 9.