Sample code for 30+ languages & platforms
Zig

JSON PathPrefix Example

Demonstrates the JSON object's PathPrefix property.

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 json = try chilkat.JsonObject.init();
    defer json.deinit();

    json.setPathPrefix("company.billing.");

    json.updateString("company_name", "TechNova Solutions Inc.") catch {};
    json.updateString("address_line_1", "123 Innovation Drive") catch {};
    json.updateString("address_line_2", "Suite 450") catch {};
    json.updateString("city", "Seattle") catch {};
    json.updateString("state_province", "WA") catch {};
    json.updateString("postal_code", "98101") catch {};
    json.updateString("country", "USA") catch {};

    json.setEmitCompact(false);

    std.debug.print("{s}\n", .{try json.emit(alloc)});

    // Result:

    // {
    //   "company": {
    //     "billing": {
    //       "company_name": "TechNova Solutions Inc.",
    //       "address_line_1": "123 Innovation Drive",
    //       "address_line_2": "Suite 450",
    //       "city": "Seattle",
    //       "state_province": "WA",
    //       "postal_code": "98101",
    //       "country": "USA"
    //     }
    //   }
    // }

    const city = try json.stringOf(alloc, "city");
    std.debug.print("city = {s}\n", .{city});
}