Module: JSON

Defined in:
opal/stdlib/json.rb

Overview

backtick_javascript: true

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.



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



96
97
98
99
100
101
# File 'opal/stdlib/json.rb', line 96

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

  `to_opal(js_object, options)`
end

.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