pub enum Json {
Null,
Bool(bool),
Number(f64),
String(String),
Array(Vec<Json>),
Object(BTreeMap<String, Json>),
}Expand description
A parsed JSON value.
Object keys are kept in a BTreeMap so serialization is deterministic,
which keeps test assertions and HTTP caching stable.
Variants§
Implementations§
Source§impl Json
impl Json
Sourcepub fn object<K: Into<String>, I: IntoIterator<Item = (K, Json)>>(
pairs: I,
) -> Self
pub fn object<K: Into<String>, I: IntoIterator<Item = (K, Json)>>( pairs: I, ) -> Self
Build an object from pairs: Json::object([("id", 1.into())]).
Sourcepub fn get(&self, path: &str) -> Option<&Json>
pub fn get(&self, path: &str) -> Option<&Json>
Look up a nested value with a dotted path: value.get("user.name").
Numeric segments index into arrays, so items.0.id works too.
pub fn as_str(&self) -> Option<&str>
pub fn as_f64(&self) -> Option<f64>
pub fn as_i64(&self) -> Option<i64>
pub fn as_bool(&self) -> Option<bool>
pub fn as_array(&self) -> Option<&[Json]>
pub fn as_object(&self) -> Option<&BTreeMap<String, Json>>
pub fn is_null(&self) -> bool
Sourcepub fn to_string_pretty(&self) -> String
pub fn to_string_pretty(&self) -> String
Serialize with two-space indentation, for config files and debug output.
Trait Implementations§
impl StructuralPartialEq for Json
Auto Trait Implementations§
impl Freeze for Json
impl RefUnwindSafe for Json
impl Send for Json
impl Sync for Json
impl Unpin for Json
impl UnsafeUnpin for Json
impl UnwindSafe for Json
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more