Do the JSON keys have to be surrounded by quotes?

christianvuerings picture christianvuerings · Jun 4, 2009 · Viewed 81.2k times · Source

Example: Is the following code valid against the JSON Spec?

{
    precision: "zip"
}

Or should I always use the following syntax? (And if so, why?)

{
    "precision": "zip"
}

I haven't really found something about this in the JSON specifications. Although they use quotes around their keys in their examples.

Answer

cobbal picture cobbal · Jun 4, 2009

Yes, you need quotation marks. This is to make it simpler and to avoid having to have another escape method for javascript reserved keywords, ie {for:"foo"}.