Zig Requires Chilkat v11.4.0+
Zig
Example: JsonObject.NewArrayOf method
See more JSON Examples
Demonstrates theNewArrayOf method.
Chilkat Zig Downloads
const std = @import("std");
const chilkat = @import("chilkat");
pub fn main(init: std.process.Init) !void {
const alloc = init.arena.allocator();
const big_cats = "[\"lion\",\"tiger\",\"leopard\",\"jaguar\",\"cheetah\",\"snow leopard\",\"clouded leopard\",\"cougar\",\"puma\",\"panther\"]";
const json = try chilkat.JsonObject.init();
defer json.deinit();
json.updateString("test", "abc") catch {};
json.newArrayOf("big_cats", big_cats) catch {
std.debug.print("{s}\n", .{try json.getLastErrorText(alloc)});
return;
};
json.setEmitCompact(false);
std.debug.print("{s}\n", .{try json.emit(alloc)});
// Result:
// {
// "test": "abc",
// "big_cats": [
// "lion",
// "tiger",
// "leopard",
// "jaguar",
// "cheetah",
// "snow leopard",
// "clouded leopard",
// "cougar",
// "puma",
// "panther"
// ]
// }
}