Sha256: 411c1a8ef27607b510d623f5b8dda63226c5892252d4da83cde6de5e498e1a6a
Contents?: true
Size: 1.23 KB
Versions: 3
Compression:
Stored size: 1.23 KB
Contents
require 'json/ext' require 'json/json2' module JSON class JSONError < StandardError; end class ParseError < JSONError; end def self.parse(source, opts = nil) `var json = JSON.parse(source); var to_opal = function(value) { switch (typeof value) { case 'string': return value; case 'number': return value; case 'boolean': return value ? Qtrue : Qfalse; case 'null': return nil; case 'object': if (!value) return nil; if (Object.prototype.toString.apply(value) === '[object Array]') { var arr = []; for (var i = 0, ii = value.length; i < ii; i++) { arr.push(to_opal(value[i])); } return arr; } else { var hash = VM.H(), v, assoc; for (var k in value) { if (Object.hasOwnProperty.call(value, k)) { v = to_opal(value[k]); assoc = k.$hash(); hash.$keys.push(k); hash.$assocs[assoc] = v; } } } return hash; } }; return to_opal(json);` end def self.generate(obj, opts = nil) end end
Version data entries
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
opal-0.3.2 | gems/json/lib/json.rb |
opal-0.3.1 | gems/json/lib/json.rb |
opal-0.3.0 | gems/json/lib/json.rb |