Module: JSON
- Defined in:
- lib/yajl/json_gem/parsing.rb,
lib/yajl/json_gem/encoding.rb
Defined Under Namespace
Classes: ParserError
Class Method Summary collapse
- .default_options ⇒ Object
- .dump(obj, io = nil, *args) ⇒ Object
- .generate(obj, opts = {}) ⇒ Object
- .load(input, *args) ⇒ Object
- .parse(str, opts = JSON.default_options) ⇒ Object
- .pretty_generate(obj, opts = {}) ⇒ Object
Class Method Details
.default_options ⇒ Object
7 8 9 |
# File 'lib/yajl/json_gem/parsing.rb', line 7 def self. @default_options ||= {:symbolize_keys => false} end |
.dump(obj, io = nil, *args) ⇒ Object
40 41 42 43 44 45 46 |
# File 'lib/yajl/json_gem/encoding.rb', line 40 def self.dump(obj, io=nil, *args) begin Yajl::Encoder.encode(obj, io) rescue Yajl::ParseError => e raise JSON::ParserError, e. end end |
.generate(obj, opts = {}) ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/yajl/json_gem/encoding.rb', line 16 def self.generate(obj, opts={}) begin = {} if opts.has_key?(:indent) [:pretty] = true [:indent] = opts[:indent] end Yajl::Encoder.encode(obj, ) rescue Yajl::ParseError => e raise JSON::ParserError, e. end end |
.load(input, *args) ⇒ Object
19 20 21 22 23 24 25 |
# File 'lib/yajl/json_gem/parsing.rb', line 19 def self.load(input, *args) begin Yajl::Parser.parse(input, ) rescue Yajl::ParseError => e raise JSON::ParserError, e. end end |
.parse(str, opts = JSON.default_options) ⇒ Object
11 12 13 14 15 16 17 |
# File 'lib/yajl/json_gem/parsing.rb', line 11 def self.parse(str, opts=JSON.) begin Yajl::Parser.parse(str, opts) rescue Yajl::ParseError => e raise JSON::ParserError, e. end end |
.pretty_generate(obj, opts = {}) ⇒ Object
29 30 31 32 33 34 35 36 37 38 |
# File 'lib/yajl/json_gem/encoding.rb', line 29 def self.pretty_generate(obj, opts={}) begin = {} [:pretty] = true [:indent] = opts[:indent] if opts.has_key?(:indent) Yajl::Encoder.encode(obj, ) rescue Yajl::ParseError => e raise JSON::ParserError, e. end end |