Skip to content


Subversion checkout URL

You can clone with
Download ZIP


`sinatra/json` fails with `NameError` #103

leafduo opened this Issue · 3 comments

4 participants


I'm using sinatra-contrib 1.4.0, and #json method doesn't work properly, it throws this:

NameError - uninitialized constant MultiJson:
        /Users/leafduo/.rvm/gems/ruby-2.0.0-p0/gems/sinatra-contrib-1.4.0/lib/sinatra/json.rb:125:in `block in <module:Sinatra>'
        /Users/leafduo/.rvm/gems/ruby-2.0.0-p0/gems/sinatra-contrib-1.4.0/lib/sinatra/json.rb:109:in `resolve_encoder'
        /Users/leafduo/.rvm/gems/ruby-2.0.0-p0/gems/sinatra-contrib-1.4.0/lib/sinatra/json.rb:99:in `json'
        api.rb:6:in `block in <main>'

The document mentioned that I can replace a encoder, so I did that and wasted a long time...

As in ff66f80, sinatra/json started using multi_json, and dropped the ability to choose encoder, we should do require 'multi_json' in our code (rather than user's code) and clean up outdated document and code (like #resolve_encoder_action).


I can confirm this also.

Added dependencies to my gemspec:

  gem.add_dependency "json", "~> 1.7.7"
  gem.add_dependency "multi_json", "~> 1.7.3"

And added a required clause into my application. Thanks @leafduo for the workaround.


Fixed by #96

@zzak zzak closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.