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

Example: JsonObject.NewArrayOf method

See more JSON Examples

Demonstrates the NewArrayOf method.

Chilkat Rust Downloads

Rust

let big_cats = "[\"lion\",\"tiger\",\"leopard\",\"jaguar\",\"cheetah\",\"snow leopard\",\"clouded leopard\",\"cougar\",\"puma\",\"panther\"]".to_string();

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

let _ = json.update_string("test", "abc");

if json.new_array_of("big_cats", &big_cats).is_err() {
    println!("{}", json.last_error_text());
    return;
}

json.set_emit_compact(false);
println!("{}", json.emit().unwrap_or_default());

// Result:

// {
//   "test": "abc",
//   "big_cats": [
//     "lion",
//     "tiger",
//     "leopard",
//     "jaguar",
//     "cheetah",
//     "snow leopard",
//     "clouded leopard",
//     "cougar",
//     "puma",
//     "panther"
//   ]
// }