By default it will try to call to_json on the object, but if
it doesn't respond to that message, it will use its own rather simple
encoder. You can easily change that anyways. To use JSON,
simply require it:

require'json'

The same goes for Yajl::Encoder:

require'yajl'

For other encoders, besides requiring them, you need to define the
:json_encoder setting. For instance, for the
Whatever encoder:

The json helper will also take two options
:encoder and :content_type. The values of this
options are the same as the :json_encoder and
:json_content_type settings, respectively. You can also pass
those to the json method: