Module: JSON

Defined in:
/Users/elia/Code/opal-docs/opal/stdlib/json.rb

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.create_idObject

Returns the value of attribute create_id


56
57
58
# File '/Users/elia/Code/opal-docs/opal/stdlib/json.rb', line 56

def create_id
  @create_id
end

Class Method Details

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


61
62
63
64
65
66
67
# File '/Users/elia/Code/opal-docs/opal/stdlib/json.rb', line 61

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

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


93
94
95
96
97
98
99
100
101
102
103
104
# File '/Users/elia/Code/opal-docs/opal/stdlib/json.rb', line 93

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


82
83
84
85
86
87
# File '/Users/elia/Code/opal-docs/opal/stdlib/json.rb', line 82

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


89
90
91
# File '/Users/elia/Code/opal-docs/opal/stdlib/json.rb', line 89

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

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


77
78
79
# File '/Users/elia/Code/opal-docs/opal/stdlib/json.rb', line 77

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

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


69
70
71
# File '/Users/elia/Code/opal-docs/opal/stdlib/json.rb', line 69

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

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


73
74
75
# File '/Users/elia/Code/opal-docs/opal/stdlib/json.rb', line 73

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