Reads and parses a JSON file.
const managed_user = try zul.fs.readJson(User, allocator, "/tmp/data.json", .{});
defer managed_user.deinit();
const user = managed_user.value;
allocator: std.mem.Allocator
The allocator to use for any memory allocations needed to parse the JSON or create T.
path: []const u8
Absolute or relative path to the file.
opts: std.json.ParseOptions
Options that control the parsing. The allocate field will be forced to alloc_always.
On success, readJson(T, ...) returns a zul.Managed(T) which exposes a deinit() method as well as the the parsed value in the value: T field.
Parsing JSON and creating T likely requires memory allocations. These allocations are done within an std.heap.ArenaAllocator. Thus, the parsed value: T has a lifetime tied to the arena. When zul.Manage(T).deinit() is called, the arena is cleared and freed.
zul.Manage is a renamed std.json.Parsed(T) (I dislike the name std.json.Parsed(T) because it represents data and behavior that has nothing to with with JSON or parsing).