Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 886171
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T13:01:33+00:00 2026-05-15T13:01:33+00:00

Rails 2.3.6 started using the fast new json library, yajl-ruby , if available .

  • 0

Rails 2.3.6 started using the fast new json library, yajl-ruby, “if available”.

In the “JSON gem Compatibility API” section of the yajl-ruby readme it outlines a method to just drop in yajl-ruby inclusion and have the rest of the app seamlessly pick it up.

So, ideally, I’d like

  1. Rails to use it
  2. My gems to use it
  3. My application code to use it

What’s the easiest way to achieve this? My guess:

config.gem 'yajl-ruby', :lib => 'yajl/json_gem'

As the very first gem in environment.rb. Doing this doesn’t result in any errors, but I’m not sure how to know if rails is picking it up for its own use.

Thanks!
John

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T13:01:35+00:00Added an answer on May 15, 2026 at 1:01 pm

    I’d recommend using yajl-ruby‘s API directly instead of the JSON gem compatibility API mainly for the reason that the JSON gem’s to_json method conflict with ActiveSupport and has had long-standing issues making them work together.

    If you just do config.gem 'yajl-ruby', :lib => 'yajl' instead, you’ll need to use Yajl::Parser and Yajl::Encoder directly to parse/encode objects. The advantage of this is you’ll be certain there won’t be any conflicts with method overrides and as such, be guaranteed your JSON encoding/parsing code will work as expected.
    The disadvantage is if you’re using any gems that use the JSON gem, they’ll continue to do so but you’re own code will use yajl-ruby.

    If you wanted to, you could use your config.gem line, then in an initializer require 'yajl' so you’d have both API’s loaded. The yajl/json_gem include will override anything that’s using the JSON gem with yajl – to ensure this overrides those methods try to make sure require 'yajl/json_gem' happens last.

    If you’re using Rails 3, you can add this to an initializer:

    ActionController::Renderers.add :json do |json, options|
      json = Yajl.dump(json) unless json.respond_to?(:to_str)
      json = "#{options[:callback]}(#{json})" unless options[:callback].blank?
      self.content_type ||= Mime::JSON
      self.response_body  = json
    end
    

    To make sure render :json => ... calls use yajl-ruby as well.

    Sorry if this isn’t really answering your question but I wanted to at least give the suggestion of using yajl-ruby‘s API directly 🙂

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 460k
  • Answers 460k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer If snapshot format is not an option for you (it… May 15, 2026 at 11:52 pm
  • Editorial Team
    Editorial Team added an answer You are computing all permutations of selecting one item from… May 15, 2026 at 11:52 pm
  • Editorial Team
    Editorial Team added an answer What can be said about this class it that it… May 15, 2026 at 11:52 pm

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.