# API Reference ## Core Types ### Datamorph Main entry point for transformations. ```rust pub struct Datamorph { transforms: Vec, } impl Datamorph { /// Create a new instance from JSON specification pub fn from_json(spec: &str) -> Result /// Transform input data according to specification pub fn transform(&self, input: T) -> Result where T: Serialize, U: DeserializeOwned } ``` ### Transform Types ```rust #[derive(Debug, Deserialize)] #[serde(tag = "type")] pub enum TransformType { #[serde(rename = "field")] Field { source: String, target: String, transform: Option, }, #[serde(rename = "concat")] Concat { sources: Vec, target: String, separator: Option, }, #[serde(rename = "split")] Split { source: String, targets: HashMap, separator: Option, }, } #[derive(Debug, Deserialize)] pub struct Transform { #[serde(flatten)] pub transform_type: TransformType, pub condition: Option, } ``` ### Error Types ```rust pub enum Error { /// JSON error Json(serde_json::Error), /// Transform error Transform(String), /// Logic error Logic(String), /// Missing field MissingField(String), } ``` ## Specification Format ### Field Transform ```json { "type": "field", "source": "sourceField", "target": "targetField", "transform": "uppercase", "condition": { "!!": {"var": "sourceField"} } } ``` ### Concatenation Transform ```json { "type": "concat", "sources": ["field1", "field2"], "target": "combinedField", "separator": ", ", "condition": { "and": [ {"!!": {"var": "field1"}}, {"!!": {"var": "field2"}} ] } } ``` ### Split Transform ```json { "type": "split", "source": "fullAddress", "separator": ",", "targets": { "street": { "index": 0, "transform": "uppercase" }, "city": { "index": 1 } } } ``` ## JSONLogic Conditions Common condition patterns: ```json // Field exists {"!!": {"var": "fieldName"}} // Value equals {"==": [{"var": "field"}, "value"]} // Multiple conditions (AND) {"and": [ {"!!": {"var": "field1"}}, {"==": [{"var": "field2"}, "value"]} ]} // Multiple conditions (OR) {"or": [ {"!!": {"var": "field1"}}, {"!!": {"var": "field2"}} ]} ```