[Chicago-talk] Problem with JSON module
David Young
davidy at nationalcycle.com
Fri Oct 2 15:57:53 PDT 2009
Hi all,
I've been racking my brain trying to figure out this problem.
In the code snippet below I do something simple. I have some JSON ($unq
which is "unquoted" JSON), and $qj (quoted JSON). They are identical,
except the key:value pairs are quoted with double quotes in the latter.
Then I run "from_json" to convert each into a perl reference.
I then run "to_json" and get back the JSON I started with. (quoted or
unquoted)
But I don't understand how $u or $q are different so that the quotes are
either present or not present when performing the conversion back to JSON.
I put $u and $q side by side below showing how they are identical (other
than the reference addresses).
Help.
ydy
======START=====
use JSON;
$uqj =
'{"data":{"graphType":"bars","ticks":[[0,"02"],[1,"03"],[2,"04"],[3,"08"],[4,"09"]],"metrics":[{"label":"Welding-1","data":[[0,31.3794],[1,57.6309],[2,0],[3,40.0247],[4,43.9238]]},{\
"label":"Welding-2","data":[[0,88.2248],[1,38.5611],[2,0],[3,49.0184],[4,51.9849]]}],"note":"Dept
by Shift"}}';
$qj =
'{"data":{"graphType":"bars","ticks":[[0,"02"],[1,"03"],[2,"04"],[3,"08"],[4,"09"]],"metrics":[{"label":"Welding-1","data":[["0","31.3794"],["1","57.6309"],["2","0.0000"],["3","40.0\
247"],["4","43.9238"]]},{"label":"Welding-2","data":[["0","88.2248"],["1","38.5611"],[2,0],["3","49.0184"],["4","51.9849"]]}],"note":"Dept
by Shift"}}';
$u = from_json($uqj);
$q = from_json($qj);
print "Unquoted:\n";
print to_json($u);
print "\n";
print "Quoted:\n";
print to_json($q);
print "\n";
$end=1;
======END======
I get this:
=====START OUTPUT=====
DB<2> x $q B<3> x $u
0 HASH(0xa3b859c) HASH(0xa3b85b4)
'data' => HASH(0xa3cf7d4) 'data' => HASH(0xa3cf9cc)
'graphType' => 'bars' 'graphType' => 'bars'
'metrics' => ARRAY(0xa3d64ac) 'metrics' => ARRAY(0xa3c65bc)
0 HASH(0xa3d6f60) 0 HASH(0xa3d488c)
'data' => ARRAY(0xa3d705c) 'data' => ARRAY(0xa3d48c8)
0 ARRAY(0xa3d6f54) 0 ARRAY(0xa3d5414)
0 0 0 0
1 31.3794 1 31.3794
1 ARRAY(0xa3d71a0) 1 ARRAY(0xa3d6be8)
0 1 0 1
1 57.6309 1 57.6309
2 ARRAY(0xa3d71b8) 2 ARRAY(0xa3d6c48)
0 2 0 2
1 0.0000 1 0
3 ARRAY(0xa3d71e8) 3 ARRAY(0xa3d6c78)
0 3 0 3
1 40.0247 1 40.0247
4 ARRAY(0xa3d7218) 4 ARRAY(0xa3d6c6c)
0 4 0 4
1 43.9238 1 43.9238
'label' => 'Welding-1' 'label' => 'Welding-1'
1 HASH(0xa3d71ac) 1 HASH(0xa3d6c3c)
'data' => ARRAY(0xa3d71dc) 'data' => ARRAY(0xa3d6c84)
0 ARRAY(0xa3d7128) 0 ARRAY(0xa3d6c54)
0 0 0 0
1 88.2248 1 88.2248
1 ARRAY(0xa3d72cc) 1 ARRAY(0xa3d6d2c)
0 1 0 1
1 38.5611 1 38.5611
2 ARRAY(0xa3d72e4) 2 ARRAY(0xa3d6f48)
0 2 0 2
1 0 1 0
3 ARRAY(0xa3d72f0) 3 ARRAY(0xa3d6f78)
0 3 0 3
1 49.0184 1 49.0184
4 ARRAY(0xa3d87e0) 4 ARRAY(0xa3d6f6c)
0 4 0 4
1 51.9849 1 51.9849
'label' => 'Welding-2' 'label' => 'Welding-2'
'note' => 'Dept by Shift' 'note' => 'Dept by Shift'
'ticks' => ARRAY(0xa3d485c) 'ticks' => ARRAY(0xa3d2448)
0 ARRAY(0xa3d39c4) 0 ARRAY(0xa3d2cd4)
0 0 0 0
1 02 1 02
1 ARRAY(0xa3d6fe4) 1 ARRAY(0xa3d45a4)
0 1 0 1
1 03 1 03
2 ARRAY(0xa3d6f90) 2 ARRAY(0xa3d4580)
0 2 0 2
1 04 1 04
3 ARRAY(0xa3d6bf4) 3 ARRAY(0xa3d2460)
0 3 0 3
1 08 1 08
4 ARRAY(0xa3d3478) 4 ARRAY(0xa3d39dc)
0 4 0 4
1 09 1 09
--
I take the "Shhhh" out of IT - ydy
More information about the Chicago-talk
mailing list