Sample code for 30+ languages & platforms
Rust Requires Chilkat v11.4.0+

Example: JsonObject.NewObjectOf method

Demonstrates the NewObjectOf method.

Chilkat Rust Downloads

Rust

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
//   }
// }