views:

63

answers:

3

The following is technically invalid JSON:

{
  color: "blue",
  size: 14
}

because the property names "color" and "size" are required by the spec to be quoted, i.e.

{
  "color": "blue",
  "size": 14
}

However, I've noticed that many web services that purport to return "JSON" do not quote their property names, and hardly anybody writing Javascript will quote their property names, since Javascript doesn't require it.

Have there been any proposals to amend or fork JSON to allow unquoted property names? It seems to be a much more natural way of using the format, but I've never seen anything suggesting it should be officially adopted.

+4  A: 

The philosophy of the design of JSON appears to be keep it as simple as possible.

"Wrap property names with double quotes" beats "Wrap property names with double quotes, or single quotes, and you can leave the quotes off unless the name includes spaces or other special characters" for simplicity.

I don't think that is likely to change.

Now I'm going to stop before I go off on a rant about HTML5 design philosophy.

David Dorward
"The philosophy of the design of JSON appears to be keep it as simple as possible." Indeed: http://json.org/
T.J. Crowder
+1  A: 

I've had trouble with property names that collided with JavaScript reserved words. After fighting with a couple such problems, I keep my JSON heavily quoted when I have the choice. In my opinion, it's much safer.

Nosredna
+1  A: 

No, i doubt this will happen. If you are using a web-service that claim to return JSON but do-so invalidly, contact them. You don't fix a specification because people implement it wrong.

And let's not collude our terms, here. Yes, JSON has "JavaScript" in its name, but understand well - JSON is not Javascript.

And before you jump on me and say "But on the json.org site it says JSON is a subset of JavaScript" - yes, I know that.

Yes, technically speaking its JavaScript, but since the format is a) stricly declarative and b) usable outside of the context of JavaScript, it's best to treat it with the mindset that it's not JavaScript. It's just a data format that also happens to be native JavaScript.

Which is why you notice that "JavaScript doesn't require it". Well, that's because JavaScript doesn't, but JSON does. Which is again why I prefer to thing of JSON as "JavaScript, but not really".

Peter Bailey