unescape

Function unescape 

Source
pub fn unescape<I: AsRef<[u8]> + ?Sized>(input: &I) -> Unescape<'_> 
Expand description

Creates a streaming JSON string unescaper from a byte slice.

This function creates an iterator to unescape a byte slice representing the raw contents of a JSON string, assuming the outer quotes have already been removed.

For a more convenient way to handle complete JSON string literals (including their surrounding " quotes), see the unescape_quoted function, which automatically trims them.

The iterator will fail if the input contains invalid JSON escape sequences.

§Example

use json_escape::{unescape, unescape_quoted};

// `unescape` works on the raw content, without quotes.
let content = r#"hello\tworld"#;
assert_eq!(unescape(content), "hello\tworld");

// If you pass a full JSON literal, the quotes are treated as literal characters.
let literal = r#""hello\tworld""#;
assert_eq!(unescape(literal), "\"hello\tworld\""); // Note the quotes in the output.

// For full literals like this, `unescape_quoted` is the recommended function.
assert_eq!(unescape_quoted(literal), "hello\tworld");