pub fn to_json(
messages: &[Message],
config: &OutputConfig,
) -> Result<String, ChatpackError>Expand description
Converts messages to a JSON array string.
Same format as write_json, but returns a String instead of writing
to a file. Useful for WASM environments or API responses.
ยงExamples
use chatpack::prelude::*;
let messages = vec![Message::new("Alice", "Hello!")];
let json = to_json(&messages, &OutputConfig::new())?;
assert!(json.contains(r#""sender": "Alice""#));