All Projects → xyaman → zjson

xyaman / zjson

Licence: MIT license
Minimal json library with zero allocations

Programming Languages

Zig
133 projects
AMPL
153 projects

Labels

zjson

A very tiny json library, it allows you to get a json value from a path. Inspired by jsonparser, a Go library.

This library is useful when you dont want to parse whole JSON file, or when the structure is to complex to parse to structs. It allocates no memory.

This library is still WIP, the API might change. There can be some bugs as it's not fully tested.

API usage:

Here there is a basic example.

const input =
    \\ {
    \\   "student": [
    \\     {
    \\       "id": "01",
    \\       "name": "Tom",
    \\       "lastname": "Price"
    \\     },
    \\     {
    \\       "id": "02",
    \\       "name": "Nick",
    \\       "lastname": "Thameson"
    \\     }
    \\   ]
    \\ }
;

const lastname = try get(input, .{ "student", 1, "lastname" });
// Thameson


// Iterates an array
const students = try get(input, .{"student"});

var iter = try zjson.ArrayIterator(students);
while(try iter.next()) |s| {
    const name = try get(value.bytes, .{"name"}); 
    std.debug.print("student name: {s}\n", .{name.bytes});
}
// "student name: Tom"
// "student name: Nick"

For more usage examples, you can check ytmusic-zig.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].