Module: JSON

Defined in:
opal/stdlib/json.rb

Defined Under Namespace

Classes: JSONError, ParserError

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.create_idObject

Returns the value of attribute create_id.



68
69
70
# File 'opal/stdlib/json.rb', line 68

def create_id
  @create_id
end

Class Method Details

.[](value, options = {}) ⇒ Object



73
74
75
76
77
78
79
# File 'opal/stdlib/json.rb', line 73

def self.[](value, options = {})
  if String === value
    parse(value, options)
  else
    generate(value, options)
  end
end

.dump(obj, io = nil, limit = nil) ⇒ Object



105
106
107
108
109
110
111
112
113
114
115
116
# File 'opal/stdlib/json.rb', line 105

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



94
95
96
97
98
99
# File 'opal/stdlib/json.rb', line 94

def self.from_object(js_object, options = {})
  options[:object_class] ||= Hash
  options[:array_class]  ||= Array

  `to_opal(js_object, options.$$smap)`
end

.generate(obj, options = {}) ⇒ Object



101
102
103
# File 'opal/stdlib/json.rb', line 101

def self.generate(obj, options = {})
  obj.to_json(options)
end

.load(source, options = {}) ⇒ Object



89
90
91
# File 'opal/stdlib/json.rb', line 89

def self.load(source, options = {})
  from_object(`$parse(source)`, options)
end

.parse(source, options = {}) ⇒ Object



81
82
83
# File 'opal/stdlib/json.rb', line 81

def self.parse(source, options = {})
  from_object(`$parse(source)`, options.merge(parse: true))
end

.parse!(source, options = {}) ⇒ Object



85
86
87
# File 'opal/stdlib/json.rb', line 85

def self.parse!(source, options = {})
  parse(source, options)
end