[jQuery] Re: json syntax question (ticket vs unticked names)

2009-05-08 Thread Thomas Matthijs
Both are valid javascript, but only one is valid json. However many json parsers are leaniant in what they accept. var moo = { foo: "bar" } // this is javascript, not json. JSON.stringify(moo) should give '{ "foo": "bar" }' // this is json. So if you are passing json to something, it needs to be

[jQuery] Re: json syntax question (ticket vs unticked names)

2009-05-08 Thread Mihailo Vasiljevic
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, do

[jQuery] Re: json syntax question (ticket vs unticked names)

2009-05-08 Thread Shawn
This isn't the same thing. Consider the following code: var json1 = { jack: "jack jackson" }; var json2 = '{ sara: "sara jones" }'; In this case, json1 becomes a javascript object in memory. json2 is a string that just so happens to look like a javascript object. In the first case, this is

[jQuery] Re: json syntax question (ticket vs unticked names)

2009-05-08 Thread unwiredbrain
Actually, quoting is optional *EXCEPT* if member name contains spaces or is a language-specific reserved word. Try to jslint this fragment: var JSONTest = { "jack johnson": "john jackson", "alice": "bob", "var": "error" }; Unquoting alice makes no difference; doing the same for jack

[jQuery] Re: json syntax question (ticket vs unticked names)

2009-05-08 Thread aldana
OK, to be standard I will go for the ticked way. Never the less I think it is unfortunate that JSON forces the name to be ticked. The JSON document gets less readable and more annoying to write. Shawn Grover wrote: > > > This all depends on where you are generating and using the json string

[jQuery] Re: json syntax question (ticket vs unticked names)

2009-05-08 Thread Shawn
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 ofte

[jQuery] Re: json syntax question (ticket vs unticked names)

2009-05-08 Thread Steven Yang
seriously i am not sure but sometimes i just hate to see something like var data = {.something}; var config = { data : data }; so when this happens I do var config = { 'data' : data }; just to be clear