This all depends on where you are generating and using the json string.
Doing
{ key : "value" }
and then using that code immediately on the same page, typically works fine.
However, if you ever need to pass your json string to/from a server,
you'll find that this "shortcut" fails quite often.
For instance, using this shortcut to request information via $.ajax(),
often gives an odd error. While the request has a 200 status (meaning
the request succeeded without error), the error handler function (if
specified) would trigger - even though it "appears" the json is correct.
(disclaimer - I haven't done this since 1.2.x days, so don't know if
it's still the case)
To avoid these errors, use the "standard" and do
{ "key" : "value" }
especially when passing json via an http request (i.e to/from a server).
You'll have fewer problems in the long run.
My thoughts.
Shawn
aldana wrote:
i often see two different json styles to have names:
{ key : "value" }
vs
{ "key" :"value" }
looking at official sites only option 2 is correct syntax, never the less
most of the tools do also handle option 1 and don't moan about the syntax.
what you say, does it in practice not matter which option you choose?
generally i favor option 1 because it is not polluted with the "". i wonder
why this syntax wasn't official from the start....
thanks
-----
manuel aldana
aldana((at))gmx.de
software-engineering blog: http://www.aldana-online.de