Rust Requires Chilkat v11.1.0+
Rust
Create a JSON Array Containing an Object
See more JSON Examples
Creates a top-level JSON array containing an object.Chilkat Rust Downloads
let j_array = chilkat::JsonArray::new();
let json = chilkat::JsonObject::new();
let _ = j_array.add_object_at2(0, &json);
let _ = json.update_string("groupId", "");
let _ = json.update_string("sku", "");
let _ = json.update_string("title", "");
let _ = json.update_string("barcode", "");
let _ = json.update_string("category", "");
let _ = json.update_string("description", "");
let _ = json.update_string("images[0]", "url1");
let _ = json.update_string("images[1]", "url...");
let _ = json.update_string("isbn", "");
let _ = json.update_string("link", "");
let _ = json.update_string("linkLomadee", "");
let _ = json.update_string("prices[0].type", "");
let _ = json.update_number("prices[0].price", "0");
let _ = json.update_number("prices[0].priceLomadee", "0");
let _ = json.update_number("prices[0].priceCpa", "0");
let _ = json.update_number("prices[0].installment", "0");
let _ = json.update_number("prices[0].installmentValue", "0");
let _ = json.update_string("productAttributes.\"Atributo 1\"", "Valor 1");
let _ = json.update_string("productAttributes.\"Atributo ...\"", "Valor ...");
let _ = json.update_string("technicalSpecification.\"Especificação 1\"", "Valor");
let _ = json.update_string("technicalSpecification.\"Especificação ...\"", "Valor ...");
let _ = json.update_number("quantity", "0");
let _ = json.update_number("sizeHeight", "0");
let _ = json.update_number("sizeLength", "0");
let _ = json.update_number("sizeWidth", "0");
let _ = json.update_number("weightValue", "0");
let _ = json.update_number("declaredPrice", "0");
let _ = json.update_number("handlingTimeDays", "0");
let _ = json.update_bool("marketplace", false);
let _ = json.update_string("marketplaceName", "");
j_array.set_emit_compact(false);
println!("{}", j_array.emit().unwrap_or_default());
// The output of this program is:
// [
// {
// "groupId": "",
// "sku": "",
// "title": "",
// "barcode": "",
// "category": "",
// "description": "",
// "images": [
// "url1",
// "url..."
// ],
// "isbn": "",
// "link": "",
// "linkLomadee": "",
// "prices": [
// {
// "type": "",
// "price": 0,
// "priceLomadee": 0,
// "priceCpa": 0,
// "installment": 0,
// "installmentValue": 0
// }
// ],
// "productAttributes": {
// "Atributo 1": "Valor 1",
// "Atributo ...": "Valor ..."
// },
// "technicalSpecification": {
// "Especificação 1": "Valor",
// "Especificação ...": "Valor ..."
// },
// "quantity": 0,
// "sizeHeight": 0,
// "sizeLength": 0,
// "sizeWidth": 0,
// "weightValue": 0,
// "declaredPrice": 0,
// "handlingTimeDays": 0,
// "marketplace": false,
// "marketplaceName": ""
// }
// ]