fast_jsonparser icon indicating copy to clipboard operation
fast_jsonparser copied to clipboard

.optimize_rails() ?

Open feliperaul opened this issue 5 years ago • 3 comments

Oj has a very nice Oj.optimize_rails() method that automagically makes Rails use Oj for all it's JSON needs (source: https://github.com/ohler55/oj/blob/develop/pages/Rails.md)

Is there a plan for something as easy to install in Rails for this gem?

feliperaul avatar Aug 06 '20 13:08 feliperaul

There is no such plan but surely it will be a good addition.

Are you interested in adding it ?

anilmaurya avatar Aug 06 '20 17:08 anilmaurya

oj is a parser and marshaller. (Oj.load, Oj.dump) fast_jsonparser is a parser only.

totrash avatar Dec 26 '20 22:12 totrash

FWIW: I threw this monkey patch in an initializer:

module ActiveRecord
  module Type
    class Json < ActiveModel::Type::Value
      def deserialize(value)
        return value unless value.is_a?(::String)
        FastJsonparser.parse(value)
      end
    end
  end
end

We're decoding huge arrays out of Postgres and saw a 5x improvement. Thank you!

nathancolgate avatar Aug 16 '22 21:08 nathancolgate