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

JSON AppendArray2 Example

Demonstrates the AppendArray2 function.

Chilkat Rust Downloads

Rust
let json = chilkat::JsonObject::new();
let _ = json.load("{ \"name\": \"John\", \"marbles\": 100 }");

// Append an empty array named "xyz"
let jarr = chilkat::JsonArray::new();
let _ = json.append_array2("xyz", &jarr);

println!("{}", json.emit().unwrap_or_default());
// Expected output is:   {"name":"John","marbles":100,"xyz":[]}

// Add elements to the array.
let _ = jarr.add_string_at(-1, "hello");
let _ = jarr.add_int_at(-1, 256);

println!("{}", json.emit().unwrap_or_default());
// Expected output is:  {"name":"John","marbles":100,"xyz":["hello",256]}