Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical

comment on

( #3333=superdoc: print w/replies, xml ) Need Help??

Hello wise monks.

I have a very large json formatted file that I am trying to extract specific values from. The json file looks like such:

{ "Content_ID" : { "CNBP_021687" : { "Title" : "Molecule of the Week - + Pyruvic Acid", "Type" : "Article", "Web Extension" : "doc", "WebSite" : "PublicWebSite", "WebSiteSection" : "PublicWebSite:841" }, "CNBP_021688" : { "Title" : "STEM Education Coalition Supports V +olunteer Service Legislation", "Type" : "Article", "Web Extension" : "pdf", "WebSite" : "PublicWebSite", "WebSiteSection" : "PublicWebSite:1892" }, "CNBP_021691" : { "Title" : "WCC Lectureship Award", "Type" : "Article", "Web Extension" : "doc", "WebSite" : "PublicWebSite", "WebSiteSection" : "PublicWebSite:1367" },

And my script looks like such:

#!c:/strawberry/perl/bin/perl.exe use JSON; use Data::Dumper; use warnings; use strict; use utf8; use URI::Escape; my $text; my $json =""; my $object = ""; my $item = ""; sub extract_json { my $file = shift; local $/; #enable slurp open my $fh, "<", "$file"; $json = <$fh>; return $json; } my $jobj = extract_json('C:\Temp3\articlePaagesJson.txt'); use Encode; $object = JSON::XS->new->decode (decode "UTF-8", $jobj); # print Dumper $object foreach $item (@{$object->{Content_ID}} ){ print " do nothing \n"; };

When I use data dumber the values print but I keep getting an error Not an ARRAY reference at

I am trying to exctract the content ID the title and the web extension if that helps at all. I keep trying everything and anything I see online and on the board but nothing is working.

Any help would be greatly appreciated

In reply to parsing JSON for specific entries by tevolo

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, 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, 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.
  • Log In?

    What's my password?
    Create A New User
    and the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others chilling in the Monastery: (3)
    As of 2021-03-05 03:02 GMT
    Find Nodes?
      Voting Booth?
      My favorite kind of desktop background is:

      Results (109 votes). Check out past polls.