Which characters are valid/invalid in a JSON key name?

Christophe picture Christophe · Dec 30, 2011 · Viewed 191.9k times · Source

Are there any forbidden characters in key names, for JavaScript objects or JSON strings? Or characters that need to be escaped?

To be more specific, I'd like to use "$", "-" and space in key names.

Answer

Marcelo Cantos picture Marcelo Cantos · Dec 30, 2011

No. Any valid string is a valid key. It can even have " as long as you escape it:

{"The \"meaning\" of life":42}

There is perhaps a chance you'll encounter difficulties loading such values into some languages, which try to associate keys with object field names. I don't know of any such cases, however.