Crates.io | datamorph-rs |
lib.rs | datamorph-rs |
version | 0.1.2 |
source | src |
created_at | 2024-11-02 14:03:07.542804 |
updated_at | 2024-11-02 14:16:33.652962 |
description | Data transformation library using declarative specifications |
homepage | https://openpayments.tech |
repository | https://github.com/Open-Payments/datamorph-rs |
max_upload_size | |
id | 1432901 |
size | 38,277 |
A powerful Rust library for transforming data structures using declarative specifications with JSONLogic support. Built for performance, type safety, and extensibility.
datamorph-rs
allows you to transform data structures using simple array-based specifications with JSONLogic conditions. It's designed to be easy to use while remaining flexible and extensible.
Add to your Cargo.toml
:
[dependencies]
datamorph-rs = "0.1.0"
serde_json = "1.0"
Basic example:
use datamorph_rs::Datamorph;
use serde_json::json;
// Define your transformation spec
let spec = r#"[
{
"type": "field",
"source": "name",
"target": "fullName",
"transform": "uppercase",
"condition": {
"!!": {"var": "name"}
}
},
{
"type": "concat",
"sources": ["city", "country"],
"target": "location",
"separator": ", "
}
]"#;
// Create transformer
let transformer = Datamorph::from_json(spec)?;
// Transform data
let input = json!({
"name": "john doe",
"city": "New York",
"country": "USA"
});
let result: serde_json::Value = transformer.transform(input)?;
println!("Result: {}", serde_json::to_string_pretty(&result)?);
Contributions are welcome! Please read our Contributing Guide for details.
This project is licensed under the Apache 2.0 License - see the LICENSE file for details.