enum JsonValue
pub enum JsonValue
Conforms to Equatable, Display, Debug, Index<string>, Codable.
A JSON document as a value: the six forms, a number as Int where it has no fraction or
exponent and fits an int, Float else.
Variants
Null
Bool(bool)
Int(int)
Float(float)
String(string)
Array(List<JsonValue>)
Object(Map<string, JsonValue>)
Methods
fn equals(o: JsonValue): bool
Returns whether both have the same form and content; two objects are equal with the same keys and equal values, whatever the order.
fn show(): string
Returns the compact text. A NaN or an infinity ends the text where it stands.
fn showTo(out: StringBuilder): void
fn debug(): string
fn debugTo(out: StringBuilder): void
fn index(k: string): ?JsonValue
pub fn at(i: int): ?JsonValue
Returns the element at index i, or null where the value is no array or the index is
out of it. [] on a JsonValue takes a member name, so an element is read with at.
pub fn path(p: string): ?JsonValue
Returns the value at a path such as "users[0].mail": a member by name, an element by
index; null where the path leaves the tree.
pub fn isNull(): bool
pub fn asBool(): ?bool
pub fn asInt(): ?int
pub fn asFloat(): ?float
Returns the number as a float, an Int widened; null for anything else.
pub fn asString(): ?string
pub fn asArray(): ?List<JsonValue>
pub fn asObject(): ?Map<string, JsonValue>
fn encode<E :: [Encoder]>(&e: E): void throws EncodeError
static fn decode<D :: [Decoder]>(&d: D): JsonValue throws DecodeError
pub fn reader(): JsonReader
Returns a decoder over this tree, to pass on.
pub fn read<T :: [Decode]>(): T throws DecodeError
Decodes a T out of this tree.
Errors
Throws DecodeError where the tree does not hold a T.