Skip to content
This repository has been archived by the owner on Aug 19, 2021. It is now read-only.
/ bumblebee Public archive

Bumblebee is a JSON transformer with simple built in rules that can easily be implemented by even the average user.

License

Apache-2.0, MIT licenses found

Licenses found

Apache-2.0
LICENSE-APACHE
MIT
LICENSE-MIT
Notifications You must be signed in to change notification settings

rust-playground/bumblebee

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

19 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Archived please see Proteus for a btter library.

Bumblebee   Build Status Latest Version

Bumblebee is a JSON transformer with simple built in rules that can easily be implemented by even the average user. It is designed to be extensible, simple to use and serializable for easy storage and creation within service and apps.


[dependencies]
bumblebee = "0.1"

Example usages

use bumblebee::prelude::*;
use bumblebee::errors::Result;
fn test_example() -> Result<()> {
      let trans = TransformerBuilder::default()
        .add_direct("user_id", "id")?
        .add_direct("full-name", "name")?
        .add_flatten(
               "nicknames",
               "",
               FlattenOps {
                   recursive: true,
                   prefix: Some("nickname"),
                   separator: Some("_"),
                   manipulation: None,
               },
           )?
        .add_direct("nested.inner.key", "prev_nested")?
        .add_direct("nested.my_arr[1]", "prev_arr")?
        .build()?;
    let input = r#"
        {
            "user_id":"111",
            "full-name":"Dean Karn",
            "nicknames":["Deano","Joey Bloggs"],
            "nested": {
                "inner":{
                    "key":"value"
                },
                "my_arr":[null,"arr_value",null]
            }
        }"#;
    let expected = r#"{"id":"111","name":"Dean Karn","nickname_1":"Deano","nickname_2":"Joey Bloggs","prev_arr":"arr_value","prev_nested":"value"}"#;
    let res = trans.apply_from_str(input)?;
    assert_eq!(expected, serde_json::to_string(&res)?);
    Ok(())
}

or when you want to do struct to struct transformations

use bumblebee::prelude::*;
use bumblebee::errors::Result;
use serde::{Serialize, Deserialize};
fn test_struct() -> Result<()> {
    #[derive(Debug, Serialize)]
    struct From {
        existing: String,
    }
    #[derive(Debug, Deserialize, PartialEq)]
    struct To {
        new: String,
    }
    let trans = TransformerBuilder::default()
        .add_direct("existing", "new")?
        .build()?;
    let from = From {
        existing: String::from("existing_value"),
    };
    let expected = To {
        new: String::from("existing_value"),
    };
    let res: To = trans.apply_to(from)?;
    assert_eq!(expected, res);
    Ok(())
}

License

Licensed under either of Apache License, Version 2.0 or MIT license at your option.
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in Bumblebee by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.

About

Bumblebee is a JSON transformer with simple built in rules that can easily be implemented by even the average user.

Resources

License

Apache-2.0, MIT licenses found

Licenses found

Apache-2.0
LICENSE-APACHE
MIT
LICENSE-MIT

Stars

Watchers

Forks

Packages

No packages published

Languages