FixUtil Documentation

Back to summary

import "util/json";

Classes

JSON class

This class wraps the JSON data structure. Normal types (integers, floats, strings, arrays, hashes) are used for the values so you can access it directly without the convenience of this class too. However some types don't directly map: null, boolean, long and double. These are represented by special classes with their constraints.

Encode/decode

static function parse(data: Byte[]): JSON
static function parse(data: Byte[], strict: Boolean): JSON
static function parse_string(s: String): JSON
static function parse_string(s: String, strict: Boolean): JSON
Parses JSON (either from UTF-8 encoded byte array or a string). Optionally you can disable strict mode to allow parsing non-standard JSONs.
function to_bytes(): Byte[]
Converts the value to JSON byte array (UTF-8 encoded).
function to_string(): String
Converts the value to JSON string.

Value access

function get(key): JSON
function get(key, default_value): JSON
Returns a value for given key, either an integer for arrays or a string for objects. It can optionally return a default value instead of an error.
function opt(key): JSON
A variant of the get function that returns a special no value marker in case the key is not found (or there is some other problem such as type mismatch). You can check the presence of an actual value by calling the has_value method. Also the various methods to get values simply return a reasonably safe default value (such as zeros, empty arrays etc.) when used on the no value marker.
function length(): Integer
Returns the number of values (valid for arrays and objects only).
function get_keys(): String[]
Returns the list of keys in an object.
function has_value(): Boolean
Returns true when the value returned by the opt method is an actual value.
function is_null(): Boolean
Returns whether the value is JSON's null value.
function is_boolean(): Boolean
Returns whether the value is JSON's boolean value.
function is_int(): Boolean
Returns whether the value is an integer.
function is_long(): Boolean
Returns whether the value is JSON's long value.
function is_float(): Boolean
Returns whether the value is a float.
function is_double(): Boolean
Returns whether the value is JSON's double value.
function is_string(): Boolean
Returns whether the value is a string.
function is_array(): Boolean
Returns whether the value is an array.
function is_object(): Boolean
Returns whether the value is an object.
function as_boolean(): Boolean
function as_boolean(default_value: Boolean): Boolean
Returns the value as a boolean. It can optionally return a default value instead of an error.
function as_int(): Integer
function as_int(default_value: Integer): Integer
Returns the value as an integer. It can optionally return a default value instead of an error.
function as_long(): Long
function as_long(default_value: Integer): Long
Returns the value as a long. It can optionally return a default value instead of an error.
function as_float(): Float
function as_float(default_value: Float): Float
Returns the value as a float. It can optionally return a default value instead of an error.
function as_double(): Double
function as_double(default_value: Float): Double
Returns the value as a double. It can optionally return a default value instead of an error.
function as_string(): String
function as_string(default_value: String): String
Returns the value as a string. It can optionally return a default value instead of an error.
function as_array(): JSON[]
Returns the value as an array of values.
function as_object(): JSON[String]
Returns the value as an object (hash).

JSONNull class

This class represents a JSON's null value.

Functions

static function get(): JSONNull
Returns JSON's null value.
static function is_instance(value): Boolean
Returns whether the value is a JSON's null value.

JSONBoolean class

This class represents a JSON's boolean value.

Functions

static function get(value: Boolean): JSONBoolean
Returns JSON's boolean value.
static function is_instance(value): Boolean
Returns whether the value is a JSON's boolean value.
function to_boolean(): Boolean
Returns the value as a boolean.
function to_string(): String
Returns the value as a string.

JSONLong class

This class represents a JSON's long value. As JSON has only a double type, this just wraps the exactly representable integer numbers in the range from -9007199254740992 to 9007199254740992 (53 bits).

Functions

static function create(value: Long): JSONLong
Creates a JSON's long value.
static function create(lo: Integer, hi: Integer): JSONLong
Creates a JSON's long value with given low and high 32-bit parts.
static function from_int(value: Integer): JSONLong
Creates a JSON's long value from an integer.
static function from_string(s: String): JSONLong
Creates a JSON's long value from a string.
static function is_instance(value): Boolean
Returns whether the value is a JSON's long value.
function to_int(): Integer
Returns the value as an integer. Throws an error on integer overflow.
function to_long(): Long
Returns the value as a long.
function to_string(): String
Returns the value as a string.

JSONDouble class

This class represents a JSON's double value. NaNs and infinities can't be stored.

Functions

static function create(value: Double): JSONDouble
Creates a JSON's double value.
static function create(lo: Integer, hi: Integer): JSONDouble
Creates a JSON's double value with given low and high 32-bit parts.
static function from_float(value: Float): JSONDouble
Creates a JSON's double value from a float.
static function from_string(s: String): JSONDouble
Creates a JSON's double value from a string.
static function is_instance(value): Boolean
Returns whether the value is a JSON's double value.
function to_float(): Float
Returns the value as a float.
function to_double(): Double
Returns the value as a double.
function to_string(): String
Returns the value as a string.