SebMorris has asked for the wisdom of the Perl Monks concerning the following question:

Hi experts

I have recently started writing a new perl program for my up and coming website, I need to be able to analyse some JSON code from an external site. After trying for over an hour I cannot see any solution.

I'm getting the code from this url: http://steamcommunity.com/market/listings/440/Name%20Tag/render/?count=2&start=2&query=

here is a link to a JSON parser making it easier to read: http://json.parser.online.fr/

I ended up with this code.

use JSON::XS; use WWW::Mechanize; use HTTP::Cookies; use LWP::Simple;; use strict; use warnings; sub parse { my $code = get("http://steamcommunity.com/market/listings/440/" . +$crates{$_[0]} . "/render/?count=1&start=0&query="); my %json = decode_json $code; print %json{success}; }

As you may have guessed this is not working, I cant think of any other way to do it. I get these errors: syntax error at C:\Users\Seb\perl.pl line 26, near "%jso syntax error at C:\Users\Seb\perl.pl line 28, near "}"

Any help would be really greatly appreciated, thanks in advance Seb Morris

Replies are listed 'Best First'.
Re: Parsing JSON code.
by Your Mother (Archbishop) on May 17, 2014 at 19:10 UTC

    Your code contains errors and won't even compile. :{ Here is a minimal example of what you're trying to do. Note that JS's true becomes a plain 1 in perlsprak.

    use strict; use warnings; use JSON::XS; use LWP::Simple "get"; my $url = "http://steamcommunity.com/market/listings/440/Name%20Tag/re +nder/?count=2&start=2"; my $json = get $url; my $data = decode_json $json; print $data->{success}, "\n";

      Thanks so much for your reply! Sorry for asking such an obvious question, i think more reading is in order :).

Re: Parsing JSON code.
by Laurent_R (Canon) on May 17, 2014 at 21:24 UTC
    Something ought to be wrong in the original post. As far as I can say, you were quite lucky that Your Mother was able to guess what was wrong and help you. Frankly, reading your 12-line code, I had no idea on how to help you on an error occurring on line 26 of your program (even if I should admit that I am not really familiar with the JSON modules). Next time you need help, please try to make your question more helpful. Please help us to help you.