postrank-labs/goliath — Issue #114: Rack::Reloader causes JSON responses to be n-escaped
Author: marcweil
Created: 2011-12-11 18:20:35+00:00
State: open

This is what my API looks like.

```ruby
require 'goliath'

class RawFileApp < Goliath::API
use Goliath::Rack::Params # parse & merge query and body parameters
use Goliath::Rack::DefaultMimeType # cleanup accepted media types
use Goliath::Rack::Formatters::JSON # JSON output formatter
use Goliath::Rack::Render # auto-negotiate response format

def response(env)
obj = {
somekey: 'val',
otherkey: 42
}
[200, { 'Content-Type' => 'application/json' }, obj]
end
end
```

When I first start the server with `ruby server.rb -sv` the response from the server is, correctly,

```javascript
{"somekey":"val","otherkey":42}
```

However if I write out the contents of the Ruby file once and reload the page (which causes Rack::Reloader to trigger, according to console output), the output becomes

```javascript
["{\"somekey\":\"val\",\"otherkey\":42}"]
```

and when I save it a third time it becomes

```javascript
["[\"{\\\"somekey\\\":\\\"val\\\",\\\"otherkey\\\":42}\"]"]
```

I have the `json_pure` gem installed and I do not see warnings on the console about `ok_json` being used.