Rust Requires Chilkat v11.4.0+
Rust
Example: JsonObject.NewObjectOf method
Demonstrates theNewObjectOf method.
Chilkat Rust Downloads
let car = "{\"make\":\"Toyota\",\"model\":\"Camry\",\"year\":2022,\"color\":\"silver\",\"engine\":{\"type\":\"inline-4\",\"fuel\":\"gasoline\",\"horsepower\":203},\"features\":[\"bluetooth\",\"backup camera\",\"adaptive cruise control\",\"lane assist\"],\"isElectric\":false}".to_string();
let json = chilkat::JsonObject::new();
let _ = json.update_string("test", "abc");
if json.new_object_of("car", &car).is_err() {
println!("{}", json.last_error_text());
return;
}
json.set_emit_compact(false);
println!("{}", json.emit().unwrap_or_default());
// Result:
// {
// "test": "abc",
// "car": {
// "make": "Toyota",
// "model": "Camry",
// "year": 2022,
// "color": "silver",
// "engine": {
// "type": "inline-4",
// "fuel": "gasoline",
// "horsepower": 203
// },
// "features": [
// "bluetooth",
// "backup camera",
// "adaptive cruise control",
// "lane assist"
// ],
// "isElectric": false
// }
// }