{"id":1239,"date":"2022-04-01T22:35:28","date_gmt":"2022-04-01T17:05:28","guid":{"rendered":"https:\/\/restfulapi.net\/?p=1239"},"modified":"2022-04-01T22:35:29","modified_gmt":"2022-04-01T17:05:29","slug":"valid-json-key-names","status":"publish","type":"post","link":"https:\/\/restfulapi.net\/valid-json-key-names\/","title":{"rendered":"Valid Key Names in JSON"},"content":{"rendered":"\n

In JSON, data is written in form of key-value pairs. The keys are written in double quotes<\/strong> and values are written according to their data types.<\/p>\n\n\n\n

{\r\n\t\"id\" : 10,\r\n\t\"name\" : \"Lokesh\",\r\n\t\"role\" : [\"admin\", \"author\"]\r\n}<\/code><\/pre>\n\n\n\n

JSON Keys must be Valid Strings<\/h2>\n\n\n\n

According to JSON.org<\/a>, a\u00a0string<\/em>\u00a0is 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<\/strong>. <\/p>\n\n\n\n

These keys must be enclosed in the double-quotes (\"<\/code>). This means if the key name contains any double quote in it, then it must be escaped.<\/p>\n\n\n\n

{\"Some \\\"random\\\" string\" : \"value\"}<\/code><\/pre>\n\n\n\n

The following characters are invalid when used in a JSON key:<\/p>\n\n\n\n