| Module | Rufus::Json |
| In: |
lib/rufus/json.rb
|
| VERSION | = | '1.0.6' | ||
| JSON | = | { :encode => lambda { |o, opts| opts[:max_nesting] = false unless opts.has_key?(:max_nesting) | The JSON / JSON pure decoder | |
| ACTIVE_SUPPORT | = | { :encode => lambda { |o, opts| ActiveSupport::JSON.encode(o, opts) }, :pretty_encode => lambda { |o| ActiveSupport::JSON.encode(o) }, :decode => lambda { |s| decode_e(s) || ActiveSupport::JSON.decode(s) }, :error => lambda { RuntimeError } | The Rails ActiveSupport::JSON decoder | |
| ACTIVE | = | ACTIVE_SUPPORT | ||
| YAJL | = | { :encode => lambda { |o, opts| Yajl::Encoder.encode(o, opts) }, :pretty_encode => lambda { |o| Yajl::Encoder.encode(o, :pretty => true, :indent => ' ') }, :decode => lambda { |s| Yajl::Parser.parse(s) }, :error => lambda { ::Yajl::ParseError } | github.com/brianmario/yajl-ruby/ | |
| OJ | = | { :encode => lambda { |o, opts| Oj.dump(syms_to_s(o), opts.merge(:symbol_keys => false)) }, :pretty_encode => lambda { |o| Oj.dump(syms_to_s(o), :indent => 2) }, :decode => lambda { |s| Oj.load(s, :strict => true) }, :error => lambda { ::Oj::ParseError } | github.com/ohler55/oj | |
| JRJACKSON | = | { :encode => lambda { |o, opts| fix_raw_value(::JrJackson::Json.dump(syms_to_s(o))) }, :pretty_encode => lambda { |o| fix_raw_value(::JrJackson::Json.dump(syms_to_s(o))) }, :decode => lambda { |s| ::JrJackson::Json.load(s) }, :error => lambda { ::JrJackson::ParseError } | github.com/guyboertje/jrjackson | |
| NONE | = | { :encode => lambda { |o, opts| raise 'no JSON backend found' }, :pretty_encode => lambda { |o| raise 'no JSON backend found' }, :decode => lambda { |s| raise 'no JSON backend found' }, :error => lambda { raise 'no JSON backend found' } | The "raise an exception because there‘s no backend" backend | |
| E_REGEX | = | /^\d+(\.\d+)?[eE][+-]?\d+$/ |
Forces a decoder JSON/ACTIVE_SUPPORT or any lambda pair that knows how to deal with JSON.
It‘s OK to pass a symbol as well, :yajl, :json, :active (or :none).
Duplicates an object by turning it into JSON and back.
Don‘t laugh, yajl-ruby makes that faster than a Marshal copy.
In the given order, attempts to load a json lib and sets it as the backend of rufus-json.
Returns the name of lib found if sucessful.
Returns nil if no lib could be set.
The default order / list of backends is yajl, active_support, json, json/pure. When specifying a custom order/list, unspecified backends won‘t be tried for.