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

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


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.


The following characters must be escaped in JSON data to avoid any problems:

  • " (double quote)
  • \ (backslash)
  • all control characters like \n, \t

JSON Parser can help you to deal with JSON.


It is worth mentioning that while starting the keys with numbers is valid, it could cause some unintended issues.

Example:

var testObject = {    "1tile": "test value"};console.log(testObject.1tile); // fails, invalid syntaxconsole.log(testObject["1tile"]; // workaround