#[repr(C)]pub struct Json {
pub value_type: JsonType,
pub internal: JsonInternal,
}Expand description
A generic JSON value that can hold any JSON type
Fields§
§value_type: JsonTypeThe type of this JSON value
internal: JsonInternalInternal storage - interpretation depends on value_type
For objects/arrays, this contains serialized data
Implementations§
Source§impl Json
impl Json
Sourcepub fn integer(value: i64) -> Self
pub fn integer(value: i64) -> Self
Create an integer JSON value.
Note: the value is stored as f64 internally, so i64 values with
magnitude greater than 2^53 will lose precision silently.
Sourcepub fn as_bool(&self) -> OptionBool
pub fn as_bool(&self) -> OptionBool
Get as boolean (returns None if not a bool)
Sourcepub fn as_i64(&self) -> OptionI64
pub fn as_i64(&self) -> OptionI64
Get as integer (returns None if not a number or not an integer)
Sourcepub fn as_string(&self) -> OptionString
pub fn as_string(&self) -> OptionString
Get as string (returns None if not a string)
Sourcepub fn raw_string(&self) -> &str
pub fn raw_string(&self) -> &str
Get the raw internal string value (for arrays/objects this is the serialized JSON)
Source§impl Json
impl Json
Sourcepub fn parse(s: &str) -> Result<Self, JsonParseError>
pub fn parse(s: &str) -> Result<Self, JsonParseError>
Parse JSON from a string.
§Errors
Returns JsonParseError (message plus line/column) if s is not
well-formed JSON.
Sourcepub fn parse_bytes(bytes: &[u8]) -> Result<Self, JsonParseError>
pub fn parse_bytes(bytes: &[u8]) -> Result<Self, JsonParseError>
Parse JSON from bytes (UTF-8).
§Errors
Returns JsonParseError (message plus line/column) if bytes is not
well-formed UTF-8 JSON.
Sourcepub fn from_serde_value(value: Value) -> Self
pub fn from_serde_value(value: Value) -> Self
Convert from serde_json::Value
Sourcepub fn to_serde_value(&self) -> Value
pub fn to_serde_value(&self) -> Value
Convert this Json to a serde_json::Value
Sourcepub fn object(entries: JsonKeyValueVec) -> Self
pub fn object(entries: JsonKeyValueVec) -> Self
Create a JSON object from key-value pairs
Sourcepub fn to_object(&self) -> Option<JsonKeyValueVec>
pub fn to_object(&self) -> Option<JsonKeyValueVec>
Convert object to Vec
Sourcepub fn to_json_string(&self) -> AzString
pub fn to_json_string(&self) -> AzString
Serialize to JSON string (returns AzString)
Sourcepub fn to_string_pretty(&self) -> AzString
pub fn to_string_pretty(&self) -> AzString
Serialize to pretty-printed JSON string
Trait Implementations§
Source§impl Default for Json
Json::null(). A default that is JSON null, rather than an empty string
masquerading as a value.
impl Default for Json
Json::null(). A default that is JSON null, rather than an empty string
masquerading as a value.
Source§impl<'de> Deserialize<'de> for Json
Available on crate feature serde-json only.
impl<'de> Deserialize<'de> for Json
serde-json only.Source§fn deserialize<D: Deserializer<'de>>(d: D) -> Result<Self, D::Error>
fn deserialize<D: Deserializer<'de>>(d: D) -> Result<Self, D::Error>
Source§impl Display for Json
Note: the Display output is meant for human-readable / debug display.
String values are quoted but not JSON-escaped (no backslash escaping
of embedded quotes, newlines, etc.). Use to_json_string() (requires
the serde-json feature) when valid JSON output is needed.
impl Display for Json
Note: the Display output is meant for human-readable / debug display.
String values are quoted but not JSON-escaped (no backslash escaping
of embedded quotes, newlines, etc.). Use to_json_string() (requires
the serde-json feature) when valid JSON output is needed.
Source§impl Extend<Json> for JsonVec
impl Extend<Json> for JsonVec
Source§fn extend<T: IntoIterator<Item = Json>>(&mut self, iter: T)
fn extend<T: IntoIterator<Item = Json>>(&mut self, iter: T)
Source§fn extend_one(&mut self, item: T)
fn extend_one(&mut self, item: T)
extend_one)Source§fn extend_reserve(&mut self, additional: usize)
fn extend_reserve(&mut self, additional: usize)
extend_one)Source§impl FromIterator<Json> for JsonVec
impl FromIterator<Json> for JsonVec
Source§impl Serialize for Json
Available on crate feature serde-json only.
impl Serialize for Json
serde-json only.Source§fn serialize<S: Serializer>(&self, s: S) -> Result<S::Ok, S::Error>
fn serialize<S: Serializer>(&self, s: S) -> Result<S::Ok, S::Error>
Serialize as the JSON value this represents, not as its repr(C) fields.
Without this, a struct holding a Json field cannot derive
Serialize at all — and the obvious workaround, storing the payload
as a String of JSON, produces escaped JSON-inside-JSON that every
consumer has to parse twice and nothing validates.