Enum Value

A value of a valid JSON datatype.

This is what is returned from the parser, and what can be serialized back into JSON data. You may want to extract your parsed data from this enum to a more specialized data structure, to make working with it more ergonomic.

scoped enum Value
{
    Object(Hash[String, Value]),
    Array(List[Value]),
    String(String),
    Number(Double),
    Boolean(Boolean),
    Null
}

define serialize(format: *Boolean, non_finite: *Boolean): String

Converts self to a String containing JSON data.

If format is true, the output JSON will be auto-formatted with consistent spacing and indentation. If you need your JSON to be human-readable, this may be desirable - however, if working with a large amount of data, you may want to keep it disabled to keep the size of the output JSON small.

If non_finite is true (the default), non-finite values will be serialized.

define serialize_file(path: String, format: *Boolean, non_finite: *Boolean)

Utility function to write serialized JSON data to a file.

format and non_finite function identically to how they do in Value.encode.

define as_hash: Hash[String, Value]

Returns the internal Hash contained within self.

define as_list: List[Value]

Returns the internal List contained within self.

define as_string: String

Returns the internal String contained within self.

define as_double: Double

Returns the internal Double contained within self.

define as_integer: Integer

Returns the internal Double contained within self, casted to an Integer.

define as_boolean: Boolean

Returns the internal Boolean contained within self.

define get(key: String): Value

Returns the Value corresponding to key in self.

define at(index: Integer): Value

Returns the Value at index in self.

define each(fn: Function(Value))

Calls fn for each Value in self.

define each_with_key(fn: Function(String, Value))

Calls fn for each key/Value pair in self.

define each_with_index(fn: Function(Integer, Value))

Calls fn for each index/Value pair in self.