Skip to content

A Rust crate simplifying converting to and from serde_json::Value and your own types

License

Notifications You must be signed in to change notification settings

SamJBarney/Jsonable

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

17 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

jsonable

Jsonable provides a easy way to convert to and from serde_json::Value for your types while in memory, allowing you to modify the json before converting to your type.

Example

use json_patch::patch;
use serde_json::*;
use jsonable::*;

#[derive(Debug,Jsonable)]
struct Person {
    pub first_name: String,
    pub last_name: Option<String>
}

let mut doc = json!({ "first_name": "Andrew" });

let p = from_str(r#"[
        { "op": "test", "path": "/first_name", "value": "Andrew" },
        { "op": "add", "path": "/last_name", "value": "Marx" }
    ]"#).unwrap();

patch(&mut doc, &p).unwrap();

let person = Person::from_json(doc).unwrap();

assert_eq!(person.last_name, Some("Marx".into()))

Roadmap

  • Implement derive for Named Structs
  • Implement derive for Tuple Structs
  • Implement derive for Unit Structs
  • Implement derive for Enums
  • Add helper attributes to allow mapping json keys to fields/values

About

A Rust crate simplifying converting to and from serde_json::Value and your own types

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages