pub enum JsonValue {
Null,
Bool(bool),
Number(f64),
String(JsonString),
Array(Vec<JsonValue>),
Object(JsonObject),
}Expand description
A zero-dependency JSON value preserving exact object key order and IEEE-754 binary64 number semantics.
Variants§
Null
JSON null.
Bool(bool)
JSON boolean (true or false).
Number(f64)
JSON finite IEEE-754 binary64 number (non-negative zero).
String(JsonString)
JSON string (UTF-8, or WTF-8 when containing lone UTF-16 surrogates).
Array(Vec<JsonValue>)
JSON array.
Object(JsonObject)
Insertion-ordered JSON object.
Implementations§
Source§impl JsonValue
impl JsonValue
Sourcepub fn as_str(&self) -> Option<&str>
pub fn as_str(&self) -> Option<&str>
Returns the string slice if this is JsonValue::String with valid UTF-8.
Sourcepub fn as_json_string(&self) -> Option<&JsonString>
pub fn as_json_string(&self) -> Option<&JsonString>
Returns the JsonString if this is JsonValue::String.
Sourcepub fn as_array(&self) -> Option<&[JsonValue]>
pub fn as_array(&self) -> Option<&[JsonValue]>
Returns the slice of elements if this is JsonValue::Array.
Sourcepub fn as_array_mut(&mut self) -> Option<&mut Vec<JsonValue>>
pub fn as_array_mut(&mut self) -> Option<&mut Vec<JsonValue>>
Returns the mutable Vec if this is JsonValue::Array.
Sourcepub fn as_object(&self) -> Option<&JsonObject>
pub fn as_object(&self) -> Option<&JsonObject>
Returns the JsonObject if this is JsonValue::Object.
Sourcepub fn as_object_mut(&mut self) -> Option<&mut JsonObject>
pub fn as_object_mut(&mut self) -> Option<&mut JsonObject>
Returns the mutable JsonObject if this is JsonValue::Object.
Sourcepub fn parse_json(text: &str) -> Result<Self, Error>
pub fn parse_json(text: &str) -> Result<Self, Error>
Parses a JSON string into a JsonValue with full ECMAScript key order and surrogate preservation.
Sourcepub fn to_compact_json(&self) -> String
pub fn to_compact_json(&self) -> String
Serializes this value to canonical compact JSON matching ECMAScript JSON.stringify.