> and, yeah, I usually put in bare keys (sans quotes) unless necessary, too.
> Not sure why. I guess I just like the clean look.

Yah, they just seem to be wasted bytes, huh?

One thing to note, and the only reason I try to force myself to use
the quotes is for portability. If the data is "really" JSON and
expects to be consumed by languages not javascript, the quotes are
[likely] necessary, eg PHP. js and php can share a common json
fragment if they are quoted.

$d = json_decode(file("someFile.json"));
foreach($d as $item => $val){ .. }

really its just a distinction between "what js can do" and "JSON"

this isn't JSON:
var foo = { bar:function(){ .. }, baz: new Date() };

(I know you know, too, btw)

About anything can be a key in JS. (DomNodes can't, though btw, but
functions objects etc)

var bar = { a:"b", c:"d" };
var bar2 = [1,2,3,4];
var foo = {};
foo[bar] = "baz";
foo[bar2] = "baz2";

if(bar in foo){ console.log(foo[bar]); } // baz
if(bar2 in foo){ console.log(foo[bar2]); } // baz2

Fun. Thanks for the banter, Karl.

Regards,
Peter Higgins

Reply via email to