The JSON format is intentionally based on a subset of the syntax of a literal JavaScript object and the syntax of an array literal, and JavaScript objects can only contain strings as keys, so JSON keys are also strings. (OK, you can sort usage numbers as keys for JavaScript objects, but in fact they are converted to strings.)
Note that the JSON point is that it is a string representation of the data that makes it easy to exchange between programs written in different languages, running on different computers in different environments. If you want to use the object as a key, then this object must be somehow presented as a string for transmission, but then the host language will have to use the objects as keys, and this will mean that you will need a limited subset of JSON for those languages that would be just a mess.
"Given that JSON is part of JavaScript"
No, it is not. Newer browsers provide methods for creating and parsing JSON, but they are not part of the language as such, except that JSON is a string format and JavaScript can execute strings. JSON is always a string representation - it must be parsed to create an object for use in JavaScript (or other languages), and as soon as this happens, JavaScript (or other languages) process the resulting object in the same way as any other object.
(Note also that a particular JSON bit does not necessarily have any keys at all: it can just be an array, for example '["one","two","three"]' .)
nnnnnn
source share