Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

How to delete the key of a path? #8

Open
gkorland opened this issue Jul 3, 2019 · 3 comments
Open

How to delete the key of a path? #8

gkorland opened this issue Jul 3, 2019 · 3 comments

Comments

@gkorland
Copy link
Contributor

gkorland commented Jul 3, 2019

e.g.

{
   "a" : {
              "b": 1,
              "c": 2
          }
}

delete $.a.c including removing c and not setting NULL in c

to

{
   "a" : {
              "b": 1
          }
}
@freestrings
Copy link
Owner

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
        }
}));

@gkorland
Copy link
Contributor Author

gkorland commented Jul 7, 2019

Yes, I know.
I'm asking how can I achieve the key delete?

@freestrings
Copy link
Owner

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 ).

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants