I am trying to make an ruby object serialize to a json that gets digested by an API.
Thanks to this link I got to the point where I do not get an object in my Json but a string of values.{"@id":"32662787","@status":"Created","@dateTime":"2016-03-11T08:42:14.6033504"}
But the problem is the leading @ in front of the names. Is there a way to get around that?
My object class I try to serialize:
class Obj
attr_accessor :id, :status, :dateTime
def to_json
hash = {}
self.instance_variables.each do |var|
hash[var] = self.instance_variable_get var
end
hash.to_json
end
end
I do not want to use gems that are not included with ruby.
Thanks in advance!