Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

Re^3: JSON parsing issue please help

by davido (Cardinal)
on Sep 29, 2012 at 19:53 UTC ( [id://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" : "192.168.1.100" }, { "entryArray" : [ { "action" : "flag", "expires" : "00:00:00", "hitsSinceAdded" : 185, "name" : "/my/page", "priority" : 4, "rule" : "rule2", "timestamp" : "15:12:55.961" } ], "name" : "192.168.1.101" }

And the output:

, or ] expected while parsing array, at character offset 1206 (before +"(end of string)") at ./mytest.pl 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.


Dave

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 http://json.org and look at the diagrams

      Yeah and? What do you want?

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://996417]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others avoiding work at the Monastery: (6)
As of 2024-03-28 12:14 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found