I am trying to parse the result of a REST API query. The result looks like the following:

{"responseData":{"translatedText":"Ciao mondo"},"responseDetails":""," +responseStatus":200,"matches":[{"id":"424913311","segment":"Hello Wor +ld","translation":"Ciao mondo","quality":"74","reference":"","usage-c +ount":50,"subject":"All","created-by":"","last-updated-by":null,"crea +te-date":"2011-12-29 19:14:22","last-update-date":"2011-12-29 19:14:2 +2","match":1},{"id":"0","segment":"Hello World","translation":"Ciao a + tutti","quality":"70","reference":"Machine Translation provided by G +oogle, Microsoft, Worldlingo or the MyMemory customized engine.","usa +ge-count":1,"subject":"All","created-by":"MT!","last-updated-by":null +,"create-date":"2012-05-13","last-update-date":"2012-05-13","match":0 +.85}]}

I am parsing it in the following simple way, unfortunatelly I am doing something wrong...

use JSON qw( decode_json ); # From CPAN use Data::Dumper my $json_text= "...."; my $decoded_json = decode_json( $json_text ); #print Dumper $decoded_json; foreach my $value ( @{ $decoded_json->{'responseData'} } ) { print my $value->{'translatedText'} ; }

It should be something stupid I am missing...


In reply to Parsing REST API JSON by welle

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.