G'day zesys,

Welcome to the Monastery.

"... I often find it a daunting task making sense of a JSON response."

You don't say what aspects of this you find daunting. Here's a few tips.

JSON is often presented as a single string many hundreds or thousands of characters long. I typically find this impossible to read at a glance; no doubt, you do too. The solution is to format that string into a more humanly readable structure. I use "JSON Formatter and Validator" for this; if you don't like that one, there are many others available, so just search for something that better suits you.

Now that you have a readable structure, just think of each ':' as a '=>' and you have a Perl hashref. That's a slight oversimplification but, in nearly all cases, it will hold true.

# JSON: { "string" : "value", "array" : [ 1, 2, 3 ], "hash" : { "key1" : "val1", "key2" : "val2" } } # Perl: { "string" => "value", "array" => [ 1, 2, 3 ], "hash" => { "key1" => "val1", "key2" => "val2" } }

The JSON syntax is actually very simple. It's described, clearly and succinctly, in "Introducing JSON".

If you're not completely familiar with hashrefs, take a look at the Hashes section of "perlintro: Perl variable types". That section — indeed, the entirety of the perlintro page — is peppered with with links to more detailed descriptions, additional information, and more advanced, related topics: don't be put off by the idea that this page is just an introduction for complete novices.

There's also a few gotchas which may not be immediately obvious; in some cases, they're highly unintuitive. Here's a couple that have tripped me up in the past:

— Ken


In reply to Re^4: Parsing a large html with perl [JSON Tips] by kcott
in thread Parsing a large html with perl by zesys

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.