jsonpath
jsonpath copied to clipboard
How to delete the key of a path?
e.g.
{
"a" : {
"b": 1,
"c": 2
}
}
delete $.a.c including removing c and not setting NULL in c
to
{
"a" : {
"b": 1
}
}
delete function do not delete key but replace with null.
let mut selector_mut = SelectorMut::default();
let ret: Value = selector_mut
.value(json!({
"a": {
"b": 1,
"c": 2
}
}))
.str_path("$.a.c").unwrap()
.delete().unwrap()
.take().unwrap();
assert_eq!(ret, json!({
"a": {
"b": 1,
"c": null
}
}));
Yes, I know. I'm asking how can I achieve the key delete?
default operation do not delete key. because i prefer to null value instead of missing key. if you prefer to key deletion, need to optional parameter and conditional implementation. eg SelectorMut::new( option ).