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

Example: JsonObject.NewArrayOf method

See more JSON Examples

Demonstrates the NewArrayOf method.

Chilkat Zig Downloads

Zig
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"
    //   ]
    // }
}