How can I access BadgerFish notated attributes using javascript?
-
05-07-2019 - |
Question
I have created a json object from ruby with cobravsmongoose, however the attributes have the @
symbol in front of them. Whenever I try to access them with standard object notation in JavaScript, such as object.object.object.@attribute
I get a parse error. Is there another way to access these objects?
Solution
Grab your JSON as a string instead. Do a replace to clean up the @ symbols, and recreate it as JSON.
OTHER TIPS
You can also access your object attributes with subscript notation:
object.object['@attribute']
But it's better to do as @Diodeus proposed
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow