Module: MuchRails::JSON
- Defined in:
- lib/much-rails/json.rb
Overview
MuchRails::JSON is an adapter for encoding and decoding JSON values. It uses Oj to do the work: github.com/ohler55/oj#-gem
Constant Summary collapse
- InvalidError =
Class.new(TypeError)
Class Method Summary collapse
Class Method Details
.decode(json, **options) ⇒ Object
21 22 23 24 25 26 27 28 |
# File 'lib/much-rails/json.rb', line 21 def self.decode(json, **) [:mode] ||= default_mode ::Oj.load(json, ) rescue ::Oj::ParseError => ex error = InvalidError.new("Oj::ParseError: #{ex.}") error.set_backtrace(ex.backtrace) raise error end |
.default_mode ⇒ Object
12 13 14 |
# File 'lib/much-rails/json.rb', line 12 def self.default_mode :strict end |
.encode(obj, **options) ⇒ Object
16 17 18 19 |
# File 'lib/much-rails/json.rb', line 16 def self.encode(obj, **) [:mode] ||= default_mode ::Oj.dump(obj, ) end |