Module: JSON
- Defined in:
- opal/stdlib/json.rb
Overview
backtick_javascript: true
Defined Under Namespace
Classes: JSONError , ParserError
Class Attribute Summary collapse
-
.create_id ⇒ Object
Returns the value of attribute create_id.
Class Method Summary collapse
- .[](value, options = {}) ⇒ Object
- .dump(obj, io = nil, limit = nil) ⇒ Object
-
.from_object(js_object, options = {}) ⇒ Object
Raw js object => opal object.
- .generate(obj, options = {}) ⇒ Object
- .load(source, options = {}) ⇒ Object
- .parse(source, options = {}) ⇒ Object
- .parse!(source, options = {}) ⇒ Object
Class Attribute Details
.create_id ⇒ Object
Returns the value of attribute create_id.
70 71 72
# File 'opal/stdlib/json.rb', line 70 def create_id @create_id end
Class Method Details
.[](value, options = {}) ⇒ Object
75 76 77 78 79 80 81
# File 'opal/stdlib/json.rb', line 75 def self.[](value, options = {}) if String === value parse(value, options) else generate(value, options) end end
.dump(obj, io = nil, limit = nil) ⇒ Object
107 108 109 110 111 112 113 114 115 116 117 118
# File 'opal/stdlib/json.rb', line 107 def self.dump(obj, io = nil, limit = nil) string = generate(obj) if io io = io.to_io if io.responds_to? :to_io io.write string io else string end end
.from_object(js_object, options = {}) ⇒ Object
Raw js object => opal object
.generate(obj, options = {}) ⇒ Object
103 104 105
# File 'opal/stdlib/json.rb', line 103 def self.generate(obj, options = {}) obj.to_json(options) end
.load(source, options = {}) ⇒ Object
91 92 93
# File 'opal/stdlib/json.rb', line 91 def self.load(source, options = {}) from_object(`$parse(source)`, options) end
.parse(source, options = {}) ⇒ Object
83 84 85
# File 'opal/stdlib/json.rb', line 83 def self.parse(source, options = {}) from_object(`$parse(source)`, options.merge(parse: true)) end
.parse!(source, options = {}) ⇒ Object
87 88 89
# File 'opal/stdlib/json.rb', line 87 def self.parse!(source, options = {}) parse(source, options) end