in reply to Re^3: Help with JSON Module
in thread Help with JSON Module

I pasted the returned data below into www.jsonlint.com and it validated.

{ "StatusCode": 0, "StatusInfo": "Command Processed OK", "PageNumber": 0, "TotalPageCount": 1, "TotalProductCount": 1, "PageProductCount": 1, "Products": [ { "BaseProductId": "50043662", "EANBarcode": "5000175411118", "CheaperAlternativeProductId": "", "HealthierAlternativeProductId": "", "ImagePath": "http://img.tesco.com/Groceries/pi/118/5000175411118/IDSh +ot_90x90.jpg", "MaximumPurchaseQuantity": 99, "Name": "Oxo 12 Chicken Stock Cubes 71G", "OfferPromotion": "Price Drop Was £1.13 Now £1.00 ", "OfferValidity": "valid from 30/7/2012 until 9/9/2012", "OfferLabelImagePath": "http://www.tesco.com/Groceries/UIAssets/I/Site +s/Retail/Superstore/Online/Product/pos/save.png", "Price": 1, "PriceDescription": "£1.41 each", "ProductId": "254881114", "ProductType": "QuantityOnlyProduct", "UnitPrice": 1.41, "UnitType": "100g" } ] }

Replies are listed 'Best First'.
Re^5: Help with JSON Module
by remiah (Hermit) on Sep 07, 2012 at 22:07 UTC

    and it validated.

    Do you? When I tried, it highlighted for two errors.

    +ot_90x90.jpg", <==here and   
    +s/Retail/Superstore/Online/Product/pos/save.png", <==here
    

    If you see document of JSON, you will find "relaxed" option. How it goes with relaxed option?

    And Data::Dumper is useful for checking some values.

    use Data::Dumper; print Dumper $data;
    This prints the content of $data. I hope it helps you debugging.
    regards

      Thank you for trying to help. I think it does not validate because you have copied the + that the website put in. If you take them out it appears to work.

      I have looked at relaxed, but I am having trouble with the syntax. Can you help. The variable holding the returned JSON is $code.

      Thank you - James.

        I guess tobyink's reply will help you.
        How is your $code?
        This works with my environment without warning, error.
        #!/usr/bin/perl use strict; use warnings; use JSON; use Data::Dumper; my $json = JSON->new; my $code=join('', (<DATA>)); print Dumper $code; my $data = $json->decode($code); __DATA__ { "StatusCode": 0, "StatusInfo": "Command Processed OK", "PageNumber": 0, "TotalPageCount": 1, "TotalProductCount": 1, "PageProductCount": 1, "Products": [ { "BaseProductId": "50043662", "EANBarcode": "5000175411118", "CheaperAlternativeProductId": "", "HealthierAlternativeProductId": "", "ImagePath": "http://img.tesco.com/Groceries/pi/118/5000175411118/IDSh +ot_90x90.jpg", "MaximumPurchaseQuantity": 99, "Name": "Oxo 12 Chicken Stock Cubes 71G", "OfferPromotion": "Price Drop Was £1.13 Now £1.00 ", "OfferValidity": "valid from 30/7/2012 until 9/9/2012", "OfferLabelImagePath": "http://www.tesco.com/Groceries/UIAssets/I/Site +s/Retail/Superstore/ "Price": 1, "PriceDescription": "£1.41 each", "ProductId": "254881114", "ProductType": "QuantityOnlyProduct", "UnitPrice": 1.41, "UnitType": "100g" } ] }