Click here to Skip to main content
15,887,776 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Why does JSON only allow a string to be a key of a pair? Why not other types such as null, number, bool, object, array? Considering JSON is tightly related with JavaScript, could I conclude the reason from JavaScript specification (ECMA-262)? I'm totally a newbie to JavaScript, could you help me to point it out.
Maybe it's not wise using null and bool, but I think number and object are OK. Just like Hashtable in C# which allows me to store almost anything as a key. I'd like to use generic types for key not only string in some situation; value in JSON is generic, why not key.
Thanks!
Posted

1 solution

If you just go here http://www.json.org/[^] you'll see the definition of object is the first syntax diagramm. It is part of the JSON specification that the name part of a name/value pair is always a string.
Factum per definitionem.

Regards,

Manfred
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900