Hello Monks, I am new to Perl and i want to parse a JSON File, but right now i am stuck.

Right now i am able to extract data from "observations"->"op_path" which results in: "Lib::Execution", but i want to access to the "status" and extract "kind", "path", "info"

The way i am extracting the data from "observations"->"op_path" is like this

my $decoded = decode_json($json); my $aref = $decoded->{"observations"}; foreach my $element (@$aref){ $final .= $element->{"op_path"}.","; } print $final;

The json file is the following one:

{ "generation_date": "", "static_info": "", "justification_files": [], "test_procedure_files": [ "" ], "observations": [ { "op_path": "Lib::Execution", "c_op_name": "Lib", "mono_info": "", "status": [ { "kind": "I", "path": "_L7=", "info": "%(MinorFrameCnt)%", "stat": "O" }, { "kind": "I", "path": "_L2=", "info": "%(Offset)%", "stat": "O" }, { "kind": "I", "path": "_L1=", "info": "%(Period)%", "stat": "O" }, { "kind": "I", "path": "_L6=-1", "info": "%(_L3)% = _L8", "stat": "O" }, { "kind": "I", "path": "_L6=-2", "info": "_L3 = %(_L8)%", "stat": "O" } ] }

Hope that you guys could help me with this issue


In reply to Iterate JSON File by mijares93

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.