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
{
Array(List[Value]),
Boolean(Boolean),
Null,
Number(Double),
Object(Hash[String, Value]),
String(String)
}
define as_boolean: Boolean
Returns the internal Boolean contained within self.
ValueErrorifselfis not of typeValue.Boolean.
define as_double: Double
define as_hash: Hash[String, Value]
Returns the internal Hash contained within self.
ValueErrorifselfis not of typeValue.Object.
define as_integer: Integer
Returns the internal Double contained within self, casted to an Integer.
ValueErrorifselfis not of typeValue.Number.ValueErrorifselfis not an integer / has a fractional part.
define as_list: List[Value]
Returns the internal List contained within self.
ValueErrorifselfis not of typeValue.Array.
define as_string: String
Returns the internal String contained within self.
ValueErrorifselfis not of typeValue.String.
define at(index: Integer): Value
Returns the Value at index in self.
ValueErrorifselfis not of typeValue.Array.IndexErrorifindexis out of range.
define each(fn: Function(Value))
Calls fn for each Value in self.
ValueErrorifselfis not of typeValue.ArrayorValue.Object.
define each_with_index(fn: Function(Integer, Value))
define each_with_key(fn: Function(String, Value))
define get(key: String): Value
Returns the Value corresponding to key in self.
ValueErrorifselfis not of typeValue.Object.IndexErrorifkeyis not inself.
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 numbers (Infinity, -Infinity, and NaN) will be serialized.
ValueErrorif a non-finite number is encountered, butnon_finiteisfalse.
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.