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

Load JSON Data at Path

See more JSON Examples

Demonstrates how to load JSON data into a path within a JSON database. For example, we begin with this JSON:
{
  "a": 1,
  "b": 2,
  "c": {
    "x": 1,
    "y": 2
  }
}
Then we load {"mm": 11, "nn": 22} to "c", and the result is this JSON:
{
  "a": 1,
  "b": 2,
  "c": {
    "mm": 11,
    "nn": 22
  }
}

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();

    // Demonstrates how to load replace the data at a location within a JSON database.

    const p = "{\"a\": 1, \"b\": 2, \"c\": { \"x\": 1, \"y\": 2 } }";

    const json = try chilkat.JsonObject.init();
    defer json.deinit();
    json.load(p) catch {};
    json.setEmitCompact(false);
    std.debug.print("{s}\n", .{try json.emit(alloc)});

    const q = "{\"mm\": 11, \"nn\": 22}";

    const c = try chilkat.JsonObject.init();
    defer c.deinit();
    json.objectOf2("c", c) catch {};
    c.load(q) catch {};

    // See that x and y are replaced with mm and nn.
    std.debug.print("{s}\n", .{try json.emit(alloc)});
}