Rust Requires Chilkat v11.0.0+
Rust
Copy JSON Object from one JSON Array to Another
See more JSON Examples
Demonstrates how to copy an object in a JSON array to another JSON array.Chilkat Rust Downloads
let arr1 = chilkat::JsonArray::new();
let arr2 = chilkat::JsonArray::new();
let s = "[{\"a\":1}, {\"b\":2}, {\"c\":3}]".to_string();
let s_empty = "[]".to_string();
let _ = arr1.load(&s);
let _ = arr2.load(&s_empty);
let j_obj = chilkat::JsonObject::new();
let _ = arr1.object_at2(1, &j_obj);
let _ = arr2.add_object_copy_at(-1, &j_obj);
println!("{}", arr2.emit().unwrap_or_default());
// output is: [{"b":2}]