views:

308

answers:

2

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?

+1  A: 

Grab your JSON as a string instead. Do a replace to clean up the @ symbols, and recreate it as JSON.

Diodeus
Wouldn't that be very CPU intensive either in Ruby, or in JavaScript on the client. Wouldn't it be better to just modify the library?
Heat Miser
It's just a simple string replace. I'd do it on the client. Unless you're getting a megabyte of data it will take milliseconds. There's no complexity in the data to dance through yet - it's just a blob of text.
Diodeus
+1  A: 

You can also access your object attributes with subscript notation:

object.object['@attribute']

But it's better to do as @Diodeus proposed

Damir Zekić