Valid Key Names in JSON

In JSON, data is written in form of key-value pairs. The keys are written in double quotes and values are written according to their data types.

	"id" : 10,
	"name" : "Lokesh",
	"role" : ["admin", "author"]

JSON Keys must be Valid Strings

According to, a string is a sequence of zero or more Unicode characters, wrapped in double quotes, using backslash escapes. Any valid string can be used as a JSON key.

These keys must be enclosed in the double-quotes ("). This means if the key name contains any double quote in it, then it must be escaped.

{"Some \"random\" string" : "value"}

The following characters are invalid when used in a JSON key:

  • " (double quote) – It must be escaped.
  • \ (backslash) – It must be used to escape certain characters.
  • all control characters like \n\t

Leave a Comment