Skip to main content

json_text

Function json_text 

Source
pub fn json_text(json: &str) -> Cow<'_, str>
Expand description

json, serialized JSON such as a JSON line, with every string in it redacted as json redacts a value: object keys are left as they are. Borrowed when it has none, and only a string with an escape in it is decoded to be searched. A string never closed is left as it is.

use rig_core::redact;

let line = r#"{"text":"env\nOPENAI_API_KEY=sk-proj-abcdefghijklmnop1234"}"#;
assert_eq!(redact::json_text(line), r#"{"text":"env\nOPENAI_API_KEY=[REDACTED]"}"#);
assert!(matches!(redact::json_text(r#"{"a":"b"}"#), std::borrow::Cow::Borrowed(_)));