Skip to main content

extract_first

Function extract_first 

Source
pub fn extract_first(data: &str) -> Option<&str>
Expand description

Extract the first complete JSON fragment from a string.

Returns None if no complete JSON object or array is found.

ยงExample

use json_extractor::extract_first;

let input = r#"hello {"name": "Alice"} world"#;
assert_eq!(extract_first(input), Some(r#"{"name": "Alice"}"#));

assert_eq!(extract_first("no json here"), None);