This goes back to a previous post, which I've somewhat resolved myself, but still have one outstanding issue: I am looking to grab and store the value of each overall json line value first. Example: from the below code, I want to actually read and store in a variable through a while loop and store 1, 2, 3, etc.
{ "1": {"subject1": "value", "subject2": [{"subject3": "value", "subject +4": "value"}], "subject5": "value", "subject6": value, "subject7": "v +alue"}, "2": {"subject1": "value", "subject2": [{"subject3": "value", "subject +4": "value"}], "subject5": "value", "subject6": value, "subject7": "v +alue"}, "3": {"subject1": "value", "subject2": [{"subject3": "value", "subject +4": "value"}], "subject5": "value", "subject6": value, "subject7": "v +alue"} }
(etc...) I currently already can store subject1's value as well as the array of subject2 and grab its subject3 value.
my $jsonfeed = (above json format!) my $json = new JSON; my $data = $json->decode($jsonfeed); my $value = "$data->{1}->{subject1}"; foreach my $array(@{$data->{1}->{subject2}}){ my %hash = (); $hash{subject3} = $array->{subject3}; }
So this is all nice, but I need to store the first value of each {} sequence which is listed here as 1{}, 2{}, 3, etc as well in a variable, and then loop the whole thing in one giant while or foreach loop. I can't seem to grab every value, however, of $data->{$_}. Anyone have a good idea?

In reply to JSON Structure Question by omegaweaponZ

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.