EN
JavaScript - which characters are valid/invalid as JSON key name?
1 answers
0 points
I would like to use special characters like: -
, $
and space for key names of objects (or JSON strings).
Are there any characters that can make a key name invalid or any characters that need to be escaped?
1 answer
0 points
Any valid string is a valid key.
For example, you can even use the "
as long as you escape it:
xxxxxxxxxx
1
var object = { "Example \"quote\" as a key": 123 }
2
3
console.log(object["Example \"quote\" as a key"]); // 123
References
0 commentsShow commentsAdd comment