Sample code for 30+ languages & platforms
Rust

JSON Hex Encoding

See more JSON Examples

Let's say your JSON contains content that is hex encoded like this: \u05d1\u05d3\u05d9\u05e7

This example shows how to get the decoded string.

Chilkat Rust Downloads

Rust

let s = "{ \"example\": \"\\u05d1\\u05d3\\u05d9\\u05e7\" }".to_string();

let json = chilkat::JsonObject::new();

let _ = json.load(&s).is_ok();

// When getting the member data, it is automatically decoded.
println!("member data: {}", json.string_of("example").unwrap_or_default());

// Output:
// member data: בדיק

// When getting the full JSON, it remains encoded. This is expected and intentional.
println!("full JSON: {}", json.emit().unwrap_or_default());

// Output:
// full JSON: {"example":"\u05d1\u05d3\u05d9\u05e7"}

// To get the full JSON without the encoding, you can decode manually.
let sb = chilkat::StringBuilder::new();
let _ = json.emit_sb(&sb);
// The hex encoding used by JSON is utf-8.
let _ = sb.decode("json", "utf-8");

println!("{}", sb.get_as_string().unwrap_or_default());

// Output:
// {"example":"בדיק"}