Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

comment on

( [id://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

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



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others imbibing at the Monastery: (4)
As of 2024-04-19 06:21 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found