Class: PhusionPassenger::Utils::JSON

Inherits:
Object
  • Object
show all
Extended by:
Forwardable, Generator
Defined in:
lib/phusion_passenger/utils/json.rb

Overview

Usage:

JSON.parse(json_string) => Array/Hash
JSON.generate(object)   => json string

Run tests by executing this file directly. Pipe standard input to the script to have it parsed as JSON and to display the result in Ruby.

Defined Under Namespace

Modules: Generator

Constant Summary collapse

WSP =
/\s+/
OBJ =
/[{\[]/
HEN =
/\}/
AEN =
/\]/
COL =
/\s*:\s*/
KEY =
/\s*,\s*/
NUM =
/-?\d+(?:\.\d+)?(?:[eE][+-]?\d+)?/
BOL =
/true|false/
NUL =
/null/

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Generator

generate

Constructor Details

#initialize(data) ⇒ JSON

Returns a new instance of JSON.



58
59
60
# File 'lib/phusion_passenger/utils/json.rb', line 58

def initialize data
  @scanner = StringScanner.new data.to_s
end

Instance Attribute Details

#scannerObject (readonly) Also known as: s

Returns the value of attribute scanner.



53
54
55
# File 'lib/phusion_passenger/utils/json.rb', line 53

def scanner
  @scanner
end

Class Method Details

.parse(data) ⇒ Object



43
# File 'lib/phusion_passenger/utils/json.rb', line 43

def self.parse(data) new(data).parse end

Instance Method Details

#parseObject



62
63
64
65
# File 'lib/phusion_passenger/utils/json.rb', line 62

def parse
  space
  object
end