pub trait Remove {
// Required method
fn remove(&mut self, json_pointer: &str) -> Result<Option<Value>>;
}
Expand description
Trait used to remove Json Value’s element
Required Methods§
Implementations on Foreign Types§
Source§impl Remove for Value
impl Remove for Value
Source§fn remove(&mut self, json_pointer: &str) -> Result<Option<Value>>
fn remove(&mut self, json_pointer: &str) -> Result<Option<Value>>
§Examples: Remove an element in a table
use serde_json::Value;
use json_value_remove::Remove;
let mut array1: Value = serde_json::from_str(r#"{"my_table":["a","b","c"]}"#).unwrap();
assert_eq!(Some(Value::String("a".to_string())), array1.remove("/my_table/0").unwrap());
assert_eq!(r#"{"my_table":["b","c"]}"#, array1.to_string());
§Examples: Remove a field from an object
use serde_json::Value;
use json_value_remove::Remove;
let mut object1: Value = serde_json::from_str(r#"{"field1.0":{"field1.1":"value1.1","field1.2":"value1.2"},"field2.0":"value2.0"}"#).unwrap();
assert_eq!(Some(Value::String("value1.2".to_string())), object1.remove("/field1.0/field1.2").unwrap());
assert_eq!(r#"{"field1.0":{"field1.1":"value1.1"},"field2.0":"value2.0"}"#,object1.to_string());