pub trait Redactor {
// Required method
fn apply(&self, path: &str, current: &Value) -> Value;
}Available on crate feature
redaction only.Expand description
Trait for types that can be used to redact values.
This trait defines how a redactor transforms a value at a given path. Implementations receive both the concrete JSON Pointer path and the current value, allowing for path-aware or value-based transformations.
§Implementations
&str- Replace with a static stringString- Replace with a stringserde_json::Value- Replace with a JSON valueFn(&str, &Value) -> Value- Transform using a function
§Examples
ⓘ
// Static replacement
.redact("/id", "stable-uuid")?
// Value-based transformation (ignore path)
.redact("$..notes", |_path, val| {
if val.as_str().map(|s| s.len() > 50).unwrap_or(false) {
serde_json::json!("[REDACTED]")
} else {
val.clone()
}
})?
// Path-aware transformation
.redact("$.items[*].id", |path, _val| {
let idx = path.split('/').nth(2).unwrap_or("0");
serde_json::json!(format!("stable-id-{idx}"))
})?