Skip to main content

extract_json_array_slice

Function extract_json_array_slice 

Source
pub fn extract_json_array_slice(raw: &str) -> Option<&str>
Expand description

Extract the substring spanning the first [ and the last ] in raw.

Returns None when raw has no [, no ] after it, or when the ] does not come after the [ (e.g. "] before ["). Does not validate that the slice is valid JSON — callers must still attempt to parse the returned slice.

§Examples

use zeph_common::llm_response::extract_json_array_slice;

assert_eq!(
    extract_json_array_slice("Sure, here you go: [1, 2, 3] — hope that helps!"),
    Some("[1, 2, 3]")
);
assert_eq!(extract_json_array_slice("no brackets here"), None);