Sample code for 30+ languages & platforms
Zig

Get JSON Details from the Last REST Operation

See more REST Examples

Demonstrates Rest.GetLastJsonData, which copies operation-specific diagnostic or result information from the most recently completed method into a JsonObject. Many methods produce no JSON, in which case the object is empty.

Tip: Code to parse the returned JSON can be generated with Chilkat's online tool at https://tools.chilkat.io/jsonParse.

Background. Some Chilkat operations expose additional structured information as JSON. GetLastJsonData provides access to that information after an operation completes.

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 rest = try chilkat.Rest.init();
    defer rest.deinit();
    const b_tls = true;
    const b_auto_reconnect = true;
    rest.connect("example.com", 443, b_tls, b_auto_reconnect) catch {
        std.debug.print("{s}\n", .{try rest.getLastErrorText(alloc)});
        return;
    };

    // Copy operation-specific diagnostic or result information from the most recent method (here the
    // Connect call) into a JsonObject.  Many methods produce no JSON, in which case the object is empty.
    const json = try chilkat.JsonObject.init();
    defer json.deinit();
    rest.getLastJsonData(json);

    json.setEmitCompact(false);
    const json_str = try json.emit(alloc);
    std.debug.print("{s}\n", .{json_str});
    // JSON parsing code for this result can be generated at Chilkat's online tool:
    // https://tools.chilkat.io/jsonParse
}