pub trait JsonObjectXlf {
// Required methods
fn insert_s<T: Serialize>(&mut self, k: &str, v: T) -> Option<Json>;
fn take_with_prefix(&mut self, prefix: &str) -> Self;
fn merge_to<T, S, K>(&self, dst: &mut T, skip: &S) -> Result<()>
where T: Serialize + DeserializeOwned,
S: ?Sized + Contains<K, str>,
K: Hash + Ord + Eq + Borrow<str>;
fn deep_update_with(&mut self, source: Json, allow_null: bool);
}Expand description
Extension for serde_json::Value.
Required Methods§
Sourcefn insert_s<T: Serialize>(&mut self, k: &str, v: T) -> Option<Json>
fn insert_s<T: Serialize>(&mut self, k: &str, v: T) -> Option<Json>
Insert a key-value pair into a JSON object by specifying the key name and the value to be assigned to it.
§Arguments
kv: can be primitive data type, such as string references or integers.
§Examples
use serde_json::json;
use xelf::json::*;
let mut jsn = json!({});
jsn.insert_s("name", "tom");
jsn.insert_s("age", 16);
assert_eq!(jsn.get_or("name", ""), "tom");
assert_eq!(jsn.get_or("age", 16), 16);Sourcefn take_with_prefix(&mut self, prefix: &str) -> Self
fn take_with_prefix(&mut self, prefix: &str) -> Self
Collect all fields that have the specified prefix and insert them into a new object, removing the prefix from the field names before insertion.
Sourcefn merge_to<T, S, K>(&self, dst: &mut T, skip: &S) -> Result<()>
fn merge_to<T, S, K>(&self, dst: &mut T, skip: &S) -> Result<()>
Merge this JSON object to a serializable object, skip the fields in skip.
Sourcefn deep_update_with(&mut self, source: Json, allow_null: bool)
fn deep_update_with(&mut self, source: Json, allow_null: bool)
Recursively update all fields of this JSON object with another JSON object.
§Arguments
source: the source JSON object.allow_null: If set totrue, the function allows updating target fields with null values from the source object. If set tofalse, it ignores null values from the source object.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.