Am having a JSON structure as below
var myJSON = {
"userTypes": {
"@type": "Array",
"type": [
"Administrator",
"Customer",
"Guest"
]
}
}
When I try to access myJSON.userTypes.@type am getting an error “SyntaxError: Unexpected token ILLEGAL” but if I access like this myJSON.userTypes.type then am able to access the array.
So my question is,
- does the @ symbol really doesn’t matter in key even it exist ?
- What impact does this make ?
Regards,
Navin
When accessing a property in a JavaScript object you can do so with dot-notation or square-bracket notation.
If you use dot-notation, then you can only access properties which can be represented as an identifier. An identifier cannot start with an
@character.Since the property you are trying to access cannot be represented by an identifier, you are limited to square bracket notation. Such: