Skip to content

Adds new method to serde_json::Value objects that allows recursive exploration

License

Notifications You must be signed in to change notification settings

benwtrent/serde-dig

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

serde-dig

Adds new method to serde_json::Value objects that allows recursive exploration

I wanted a function similar to Ruby's Hash#dig but came up empty with searching.

When you want something done, just do it.

Example usage:

 use serde_json::json;
 use serde_dig::{Dig};
 fn main() {
     // The type of `john` is `serde_json::Value`
     let john = json!({
         "name": "John Doe",
         "age": 43,
         "phones": [
             "+44 1234567",
             "+44 2345678"
         ]
     });
     let path:&[DigIndex] = &["phones".into(), 0.into()];
     println!("first phone number: {}", john.get_deep(path).unwrap());
 }

This only really works for serde_json::Value objects. If this was to be more general, a similar algebraic union of all major types would have to be used. This is because the return type is not 100% known (nested vectors, maps, oh my!).

About

Adds new method to serde_json::Value objects that allows recursive exploration

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages