Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?

Re^3: JSON parsing issue please help

by davido (Archbishop)
on Sep 29, 2012 at 19:53 UTC ( #996417=note: print w/replies, xml ) Need Help??

in reply to Re^2: JSON parsing issue please help
in thread JSON parsing issue please help

No, you're not getting the output you show using the JSON you posted. Look at the #@%!^ JSON you posted. It is not capable of resulting in the output you are showing. Here's what I get when I test it:

use strict; use warnings; use File::Slurp; use JSON; my $json = read_file(\*DATA); my $j = JSON->new; my %json_text = %{ $j->decode($json) }; while( my ( $key, $value ) = each %json_text ) { print "$key = $value\n"; } __DATA__ { "alertCounts" : [ { "count" : 5, "rule" : "rule1" }, { "count" : 16, "rule" : "rule2" } ], "balArray" : [ { "containerArray" : [], "name" : "user_ip" }, { "containerArray" : [ { "entryArray" : [ { "action" : "flag", "expires" : "00:00:00", "hitsSinceAdded" : 56, "name" : "/my/page", "priority" : 4, "rule" : "rule1", "timestamp" : "15:28:40.150" } ], "name" : "" }, { "entryArray" : [ { "action" : "flag", "expires" : "00:00:00", "hitsSinceAdded" : 185, "name" : "/my/page", "priority" : 4, "rule" : "rule2", "timestamp" : "15:12:55.961" } ], "name" : "" }

And the output:

, or ] expected while parsing array, at character offset 1206 (before +"(end of string)") at ./ line 12.

I don't know how many more times you need someone to tell you that the sample input you're posting isn't capable of producing any reasonable output because it's broken. Post real JSON that isn't malformed, and we can begin to talk about your code.


Replies are listed 'Best First'.
Re^4: JSON parsing issue please help
by diamondsandperls (Beadle) on Sep 29, 2012 at 20:51 UTC
    The thing im trying to parse on my end is JSON for 120% sure bc someone has parsed this with Ruby and I have seen their code; however, I want to parse this with perl just for the sake of learning.

    Rather than getting frustrated and helping just disregard. I believe one replier has already helped in letting me know the elements are in hash form.

    Has to be a typo on my end the json i posted is a snapshot of the entire file which I CAN NOT POST bc there is sensitive data in the file and the file is HUGE so posting the entire thing anyway just isn't plausible because I would have to edit the !@#$!@#$ thing!
      If this someone has parsed this JSON with their own hand-rolled parser in Ruby, then that parser is accepting invalid JSON and should be dumped in favor of one used by other Ruby projects. If this is being parsed by a popular Ruby library, alert the maintainers of that code to the JSON spec (or the RFC) epecially this part:

      array = begin-array [ value *( value-separator value ) ] end-arr +ay
      Notice that it isn't array = begin-array [ *( value value-separator ) ] end array

      I believe one replier has already helped in letting me know the elements are in hash form.

      Go to and look at the diagrams

      Yeah and? What do you want?

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://996417]
and !@monks...

How do I use this? | Other CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (7)
As of 2018-02-22 15:00 GMT
Find Nodes?
    Voting Booth?
    When it is dark outside I am happiest to see ...

    Results (294 votes). Check out past polls.