Skip to main content

from_json_string

Function from_json_string 

Source
pub fn from_json_string(slice: &[u8]) -> Option<String>
Expand description

Parse a JSON string literal (including surrounding quotes) into an unescaped String.

Returns None if slice is not a well-formed quoted string (raw controls, bad escapes, lone surrogates, missing quotes).

§Examples

use jshift::from_json_string;

assert_eq!(from_json_string(br#""say \"hi\"""#).as_deref(), Some(r#"say "hi""#));
assert_eq!(from_json_string(b"not-a-string"), None);