Module: JSON

Defined in:
opal/stdlib/json.rb

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.create_idObject

Returns the value of attribute create_id



55
56
57
# File 'opal/stdlib/json.rb', line 55

def create_id
  @create_id
end

Class Method Details

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



60
61
62
63
64
65
66
# File 'opal/stdlib/json.rb', line 60

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

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



88
89
90
91
92
93
94
95
96
97
98
99
# File 'opal/stdlib/json.rb', line 88

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



77
78
79
80
81
82
# File 'opal/stdlib/json.rb', line 77

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

  `to_opal(js_object, options.map)`
end

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



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

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

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



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

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

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



72
73
74
# File 'opal/stdlib/json.rb', line 72

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