json.cls 100.20160804 Date: 2016-08-04
Author: Brandon Cherry, Rony G. Flatscher

Overview Index
JSON 1.00



Package: JSON.CLS

Classes

PUBLIC JSON
Description: This class implements RFC 4627 and allows to encode Rexx objects as JSON strings and parse JSON strings into Rexx objects.
author Brandon W. Cherry (original author)
author Rony G. Flatscher (adapted code to ooRexx 4.2.0 and 5.0.0)
Attributes: version (GET)
Methods: encodeMapCollection encodeOrderedCollection encodeRexxObject encodeRexxString fromJSON getEncoding getJsonBOM parseJSONarray parseJSONarrayValue parseJSONobject parseJSONobjectValue parseJSONother parseJSONstring parseJSONvalue toJSON trimLeadingWhitespace unescape

PUBLIC JsonBoolean
Description: ooRexx class to represent a JSON boolean (logical) value. It inherits from the ooRexx mixinclass Comparable and therefore implements its abstract method compareTo.
Attributes: false (GET) true (GET) value (GET) version (GET)
Methods: <> = >< \= activate compareTo makeJSON makestring new


Source: test/oorexx/json/json.cls


PUBLIC Class: JSON

Metaclass: Class

Description:
This class implements RFC 4627 and allows to encode Rexx objects as JSON strings and parse JSON strings into Rexx objects.
author Brandon W. Cherry (original author)
author Rony G. Flatscher (adapted code to ooRexx 4.2.0 and 5.0.0)

Init

init
Expose: eJS uJS whitespace ctrl level indent rexx2json
Description: Constructor.

Methods Summary

PRIVATE encodeMapCollection
PRIVATE encodeOrderedCollection
PRIVATE encodeRexxObject
PRIVATE encodeRexxString
PUBLIC fromJSON
PUBLIC getEncoding CLASS
PUBLIC getJsonBOM CLASS
PRIVATE parseJSONarray
PRIVATE parseJSONarrayValue
PRIVATE parseJSONobject
PRIVATE parseJSONobjectValue
PRIVATE parseJSONother
PRIVATE parseJSONstring
PRIVATE parseJSONvalue
PUBLIC toJSON
PRIVATE trimLeadingWhitespace ABSTRACT CLASS
PUBLIC unescape CLASS

Attributes

Attribute: PUBLIC version GET CLASS
Description: Class getter attribute method that returns the version information of this class.
return version as a string, formatted as: major*100+minor || "." || yyyymmdd

Methods

Method: encodeMapCollection
Accessmodifier: PRIVATE
Returns Value: No
Expose: buffer level indent
use arg: rexxObject
Description: Encodes any ooRexx unordered collection, including directory objects. The index objects are sorted caselessly in ascending order to ease human analysis of the encoded data. If an unordered collection possesses the ALLAT method, then multiple entries per index are expected (like the ooRexx .Relation class), which will cause the encoding of multiple index entries, one per item. If the index is not a string object, then the MAKESTRING method is used to get a string object rendering representing the index object. If a MAKESTRING method is not available then the object name and its identity hash value (encoded as hexadecimal value) are used instead to represent the index object.
param rexxObject the Rexx object to encode

Method: encodeOrderedCollection
Accessmodifier: PRIVATE
Returns Value: No
Expose: buffer level indent
use arg: rexxObject
Description: Encodes any ooRexx ordered collection, including array objects.
param rexxObject the Rexx object to encode

Method: encodeRexxObject
Accessmodifier: PRIVATE
Returns Value: No
Expose: buffer
use arg: rexxObject
Description: Control method that determines which method should encode the supplied Rexx object.
param rexxObject the Rexx object to encode

Method: encodeRexxString
Accessmodifier: PRIVATE
Returns Value: No
Expose: buffer eJS level indent rexx2json
use strict arg: rexxObject, bQuote=.false
Description: Encodes a Rexx string, applying the JSON character escaping strings.
param rexxObject the Rexx object to encode

Method: fromJSON
Accessmodifier: PUBLIC
Returns Value: Yes
Expose: jsonString jsonPos jsonStringLength
use strict arg: jsonString
Description: Converts a JSON encoded string to Rexx objects.
param jsonString some JSON encoded string

Method: getEncoding
Accessmodifier: PUBLIC
Returns Value: Yes
Option(s): CLASS
use strict arg: string=""
Description: Determines the encoding by inspecting the first four bytes of a JSON string, cf. cf.
param string optional JSON string in which the first four bytes may be a BOM (byte order mark)
return "UTF-8", "UTF-16BE", "UTF-16LE", "UTF-32BE", "UTF-32LE", depending on the BOM

Method: getJsonBOM
Accessmodifier: PUBLIC
Returns Value: Yes
Option(s): CLASS
use strict arg: encoding="UTF-8"
Description: Returns the JSON BOM (byte order mark) characters according to the desired encoding, cf. .
param encoding optional, one of "UTF-8", "UTF-16BE", "UTF-16LE", "UTF-32BE", "UTF-32LE"
return the empty string for "UTF-8" or unknown encoding or a four-character string formatted as a JSON BOM

Method: parseJSONarray
Accessmodifier: PRIVATE
Returns Value: Yes
Expose: jsonString jsonPos
Description: Converts a JSON array into a Rexx array object.
return returns the Rexx array representing the parsed JSON array

Method: parseJSONarrayValue
Accessmodifier: PRIVATE
Returns Value: Yes
Expose: jsonString
use arg: rexxArray
Description: Converts a JSON array value and appends it to a Rexx array.
param rexxArray a Rexx array to which the JSON array value gets appended

Method: parseJSONobject
Accessmodifier: PRIVATE
Returns Value: Yes
Expose: jsonString jsonPos
Description: Converts a JSON object into a Rexx Directory object or - starting with ooRexx 5.0 - into a StringTable object.

Method: parseJSONobjectValue
Accessmodifier: PRIVATE
Returns Value: Yes
Expose: jsonString jsonPos
use arg: rexxDirectory
Description: Converts and stores a JSON name:value pairs as an index/item pair in the Rexx directory object.
param rexxDirectory A Rexx directory object to store the JSON "name:value" pair as "index:item" pair

Method: parseJSONother
Accessmodifier: PRIVATE
Returns Value: Yes
Expose: jsonString ctrl jsonPos jsonStringLength
Description: Converts other json types into Rexx objects.

Method: parseJSONstring
Accessmodifier: PRIVATE
Returns Value: Yes
Expose: jsonString uJS jsonPos jsonStringLength
Description: Converts a quoted JSON string into a Rexx string. Any JSON character escapes are converted to the characters they represent.
return the Rexx string representing the JSON string

Method: parseJSONvalue
Accessmodifier: PRIVATE
Returns Value: Yes
Expose: jsonString jsonPos
Description: Control method that determines which parse method gets used.
return the Rexx object that results from parsing the entire JSON encoded string and representing it

Method: toJSON
Accessmodifier: PUBLIC
Returns Value: Yes
Expose: buffer level
use strict arg: rexxObject
Description: Converts a Rexx object to JSON formatting to pass to eval()
param rexxObject The object to converts directory, array, or string objects. Otherwise, it calls the makearray method for the object.
return a string that represents the JSON encoding of the supplied rexxObject

Method: trimLeadingWhitespace
Accessmodifier: PRIVATE
Returns Value: No
Option(s): ABSTRACT CLASS
Expose: jsonString whitespace jsonPos jsonStringLength
Description: Removes allowed whitespace between values.

Method: unescape
Accessmodifier: PUBLIC
Returns Value: No
Option(s): CLASS

Instantiated Classes

JsonBoolean



PUBLIC Class: JsonBoolean

Metaclass: Class
Inheritance(s): comparable

Description:
ooRexx class to represent a JSON boolean (logical) value. It inherits from the ooRexx mixinclass Comparable and therefore implements its abstract method compareTo.

Init

init PRIVATE
Expose: value
use strict arg: value
Description: Constructor.
param value mandatory Rexx string representing the logical value

Methods Summary

PUBLIC <>
PUBLIC =
PUBLIC >< ABSTRACT
PUBLIC \=
PUBLIC activate CLASS
PUBLIC compareTo
PUBLIC makeJSON
PUBLIC makestring
PUBLIC new CLASS

Attributes

Attribute: PUBLIC false GET CLASS
Description: Class getter attribute method that refers to the sentinel object that represents the value .false.

Attribute: PUBLIC true GET CLASS
Description: Class getter attribute method that refers to the sentinel object that represents the value .true.

Attribute: PUBLIC value GET
Description: Getter attribute method that returns the Rexx string representing the logical value.

Attribute: PUBLIC version GET CLASS
Description: Class getter attribute method that returns the version information of this class.
return version as a string, formatted as: major*100+minor || "." || yyyymmdd

Methods

Method: <>
Accessmodifier: PUBLIC
Returns Value: No
Description: Unequal comparison method, forwarding to method "\=".

Method: =
Accessmodifier: PUBLIC
Returns Value: Yes
use strict arg: other
Description: Equal comparison method.
param other the other object representing a Boolean/logical value
return .true, if this object and other can be reqarded to be equal, .false else

Method: ><
Accessmodifier: PUBLIC
Returns Value: No
Option(s): ABSTRACT
Description: Unequal comparison method, forwarding to method "\=".

Method: \=
Accessmodifier: PUBLIC
Returns Value: Yes
use strict arg: other
Description: Unequal comparison method.
param other the other object representing a Boolean/logical value
return .true, if this object and other cannot be reqarded to be equal, .false else

Method: activate
Accessmodifier: PUBLIC
Returns Value: Yes
Option(s): CLASS
Expose: true false
Description: Finalizes the class initialization by creating the two sentinel class attribute values true and false.

Method: compareTo
Accessmodifier: PUBLIC
Returns Value: Yes
Expose: value
use strict arg: other
Description: Implements the abstract method inherited from the mixinclass Comparable.

Method: makeJSON
Accessmodifier: PUBLIC
Returns Value: Yes
Expose: value
Description: Renders the object as a JSON string representing its logical value.
return a string representing its logical value JSON encoded, either "false" or "true"

Method: makestring
Accessmodifier: PUBLIC
Returns Value: Yes
Expose: value
Description: Renders the object as a Rexx string representing its logical value.
return a Rexx string representing its logical value, either "0" or "1"

Method: new
Accessmodifier: PUBLIC
Returns Value: Yes
Option(s): CLASS
Expose: true false
use strict arg: val
Description: Controls the creation of instances of this class, makes sure that the sentinel values get created and cached, otherwise returns the requested object.
param val a string representing a Boolean/logical value, i.e. one of "0", "1", "true", "false", ".true" or ".false" in any case.