pub enum RecordTransform {
Flatten {
separator: String,
},
RenameKeys {
pattern: String,
replacement: String,
},
KeysToSnakeCase,
Custom(Arc<dyn Fn(Value) -> Value + Send + Sync>),
}Expand description
A transformation applied to every record fetched by a crate::stream::RestStream.
Transforms are applied in the order they are added via
crate::config::RestStreamConfig::add_transform.
The three built-in variants are each guarded by a Cargo feature flag
(all enabled by default — see module-level docs).
RecordTransform::Custom is always available and accepts any closure.
Variants§
Flatten
Flatten nested JSON objects into a single-level map.
Nested key paths are joined with separator. Arrays are left as-is.
Requires feature transform-flatten (default).
§Example
{"user": {"id": 1, "addr": {"city": "NYC"}}} → (separator = "__")
{"user__id": 1, "user__addr__city": "NYC"}RenameKeys
Apply a single regex substitution to every key in the record.
Keys in nested objects and objects inside arrays are also renamed
recursively. pattern is a Rust regex; replacement may reference
capture groups with $1, ${name}, etc. Chain multiple RenameKeys
transforms for multi-step pipelines.
Requires feature transform-rename-keys (default).
§Example
pattern = r"^_sdc_", replacement = "" → strip "_sdc_" prefixKeysToSnakeCase
Convert all keys to snake_case using the same algorithm as Meltano’s
default key normaliser:
- Strip characters that are neither alphanumeric nor whitespace.
- Trim edges, then replace whitespace runs with
_. - Collapse consecutive underscores.
- Lowercase and trim leading/trailing underscores.
Requires feature transform-snake-case (default).
| Input key | Output key |
|---|---|
"First Name" | "first_name" |
"last-name" | "lastname" |
"price ($)" | "price" |
"ID" | "id" |
Custom(Arc<dyn Fn(Value) -> Value + Send + Sync>)
A user-supplied transformation function.
The function receives each record as a Value and returns the
(possibly modified) record. Construct one with RecordTransform::custom.
Always available — not guarded by any feature flag.
Implementations§
Source§impl RecordTransform
impl RecordTransform
Sourcepub fn custom<F>(f: F) -> Self
pub fn custom<F>(f: F) -> Self
Create a custom transform from any function or closure.
The closure receives each record as a Value and must return a
Value (the transformed record). It is called once per record and
may perform any manipulation — adding fields, removing fields, renaming,
type coercion, etc.
Custom transforms are always available regardless of feature flags.
§Example
use faucet_stream::RecordTransform;
use serde_json::{Value, json};
// Inject a constant "source" field into every record.
let stamp = RecordTransform::custom(|mut record| {
if let Value::Object(ref mut map) = record {
map.insert("_source".to_string(), json!("my-api"));
}
record
});