json-escape 0.3.1

A no_std, zero-copy, allocation-free library for streaming JSON string escaping and unescaping. Ergonomic, fast, RFC 8259 compliant, with layered APIs for iterators, I/O streaming, and low-level tokens.
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
//! Basic unescaping from a string slice into a `String`.

use json_escape::unescape;
use std::borrow::Cow;

fn main() {
    let input = r#"Emoji: \uD83D\uDE00 and a tab\t!"#;
    let expected = "Emoji: 😀 and a tab\t!";

    // `unescape` returns an iterator over Result<&[u8], _>.
    // `.decode_utf8()` collects and validates into a `Cow<str>`.
    let decoded: Cow<str> = unescape(input).decode_utf8().unwrap();

    assert_eq!(decoded, expected);
    println!("Unescaped string: {}", decoded);
}