pub enum JsonValue {
Null,
Bool(bool),
Number(JsonNumber),
String(String),
Array(Vec<JsonValue>),
Object(JsonObject),
}Expand description
An owned JSON value.
JSON has exactly six value kinds, so this enum is intentionally exhaustive —
you can match it without a wildcard arm.
Variants§
Null
null.
Bool(bool)
true or false.
Number(JsonNumber)
A number, preserving its exact source text.
String(String)
A string (decoded Unicode scalar values).
Array(Vec<JsonValue>)
An array.
Object(JsonObject)
An object with unique keys in insertion order.
Implementations§
Source§impl JsonValue
impl JsonValue
Sourcepub fn str_as<'a, T>(&'a self) -> Result<T, JsonExtractError>
pub fn str_as<'a, T>(&'a self) -> Result<T, JsonExtractError>
Reads this value as a string-backed primitive T, validating it through
T’s TryFrom<&str> constructor.
Returns JsonExtractErrorKind::WrongType if this is not a JSON string,
or JsonExtractErrorKind::Invalid if it fails validation. The error
path is the document root ($); use
JsonObject::get_str_as when the value lives under a key so the error
points at that field.
Source§impl JsonValue
impl JsonValue
Sourcepub fn is_null(&self) -> bool
pub fn is_null(&self) -> bool
Returns true if this is JsonValue::Null.
Sourcepub fn as_bool(&self) -> Option<bool>
pub fn as_bool(&self) -> Option<bool>
Returns the boolean if this is a JsonValue::Bool.
Sourcepub fn as_number(&self) -> Option<&JsonNumber>
pub fn as_number(&self) -> Option<&JsonNumber>
Returns the number if this is a JsonValue::Number.
Sourcepub fn as_str(&self) -> Option<&str>
pub fn as_str(&self) -> Option<&str>
Returns the string if this is a JsonValue::String.
Sourcepub fn as_array(&self) -> Option<&[JsonValue]>
pub fn as_array(&self) -> Option<&[JsonValue]>
Returns the array if this is a JsonValue::Array.
Sourcepub fn as_object(&self) -> Option<&JsonObject>
pub fn as_object(&self) -> Option<&JsonObject>
Returns the object if this is a JsonValue::Object.