Rust
Rust
JSON: Renaming and Deleting Members
See more JSON Examples
Demonstrates renaming and deleting members. This example uses the following JSON document:
{
"apple": "red",
"lime": "green",
"banana": "yellow",
"broccoli": "green",
"strawberry": "red"
}
Chilkat Rust Downloads
let json = chilkat::JsonObject::new();
if json.load("{\"apple\": \"red\",\"lime\": \"green\",\"banana\": \"yellow\",\"broccoli\": \"green\",\"strawberry\": \"red\"}").is_err() {
println!("{}", json.last_error_text());
return;
}
// Rename "lime" to "lemon".
let _ = json.rename("lime", "lemon").is_ok();
// Change the color to yellow:
let _ = json.set_string_of("lemon", "yellow").is_ok();
// Rename by index. Banana is at index 2 (apple is at index 0)
let _ = json.rename_at(2, "bartlett_pear").is_ok();
// Delete broccoli by name
let _ = json.delete("broccoli").is_ok();
// Delete apple by index. Apple is at index 0.
let _ = json.delete_at(0).is_ok();
json.set_emit_compact(false);
println!("{}", json.emit().unwrap_or_default());