pub enum Json {
Array(Box<[Json]>),
Object(Map<Box<str>, Json>),
String(Box<str>),
Number(f64),
True,
False,
Null,
}
Expand description
Represents a JSON object
Variants§
Implementations§
Source§impl Json
impl Json
Sourcepub fn deserialize(text: impl AsRef<str>) -> Result<Json, Error>
pub fn deserialize(text: impl AsRef<str>) -> Result<Json, Error>
Sourcepub fn deserialize_with_config(
text: impl AsRef<str>,
conf: JsonConfig,
) -> Result<Json, Error>
pub fn deserialize_with_config( text: impl AsRef<str>, conf: JsonConfig, ) -> Result<Json, Error>
Deserializes the given string into a Json object
using the given JsonConfig
Sourcepub fn serialize(&self, out: &mut dyn Write) -> Result
pub fn serialize(&self, out: &mut dyn Write) -> Result
Serializes the JSON object into a fmt::Write
Sourcepub fn get(&self, key: impl AsRef<str>) -> Option<&Json>
pub fn get(&self, key: impl AsRef<str>) -> Option<&Json>
Attempts to get a value of the given json object. If the json enum is not an Object variant, or if it doesn’t contain the key, returns None
Sourcepub fn get_mut(&mut self, key: impl AsRef<str>) -> Option<&mut Json>
pub fn get_mut(&mut self, key: impl AsRef<str>) -> Option<&mut Json>
Same as get, but with a mutable reference
Sourcepub fn nth(&self, i: usize) -> Option<&Json>
pub fn nth(&self, i: usize) -> Option<&Json>
Attempts to get a value of the given json array. If the json enum is not an Array variant, or if it doesn’t contain the key, returns None
Sourcepub fn nth_mut(&mut self, i: usize) -> Option<&mut Json>
pub fn nth_mut(&mut self, i: usize) -> Option<&mut Json>
Same as nth, but with a mutable reference
Sourcepub fn number(&self) -> Option<f64>
pub fn number(&self) -> Option<f64>
Attempts to get the inner f64 of the json object, if it is a Number variant
Sourcepub fn string(&self) -> Option<&str>
pub fn string(&self) -> Option<&str>
Attempts to get the inner String of the json object, if it is a String variant
Sourcepub fn object(&self) -> Option<&Map<Box<str>, Json>>
pub fn object(&self) -> Option<&Map<Box<str>, Json>>
Attempts to get the inner Object of the json object, if it is an Object variant
Sourcepub fn array(&self) -> Option<&[Json]>
pub fn array(&self) -> Option<&[Json]>
Attempts to get the inner Array of the json object, if it is an Array variant