I created a REST API with rails and use .to_json to convert the API output to json response. E.g. @response.to_json
The objects in the response contains created_at and updated_at fields, both Datetime
In the JSON response, both these fields are converted to strings, which is more costly to parse than unixtimestamp.
Is there a simple way I can convert the created_at and updated_at fields into unixtimestamp without having to iterate through the whole list of objects in @response?
[updated] danielM's solution works if it's a simple .to_json. However, if I have a .to_json(:include=>:object2), the as_json will cause the response to not include object2. Any suggestions on this?