Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/xyaman/zjson
Minimal json library with zero allocations
https://github.com/xyaman/zjson
json zig
Last synced: 2 months ago
JSON representation
Minimal json library with zero allocations
- Host: GitHub
- URL: https://github.com/xyaman/zjson
- Owner: xyaman
- License: mit
- Created: 2021-12-16T13:36:33.000Z (about 3 years ago)
- Default Branch: main
- Last Pushed: 2021-12-28T16:17:53.000Z (about 3 years ago)
- Last Synced: 2024-08-04T04:07:37.017Z (6 months ago)
- Topics: json, zig
- Language: Zig
- Homepage:
- Size: 15.6 KB
- Stars: 42
- Watchers: 2
- Forks: 1
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- awesome-zig - zjson🗒️Minimal json library with zero allocations
README
# zjson
A very tiny json library, it allows you to get a json value from a path.
Inspired by [jsonparser](https://github.com/buger/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.
```zig
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](https://github.com/xyaman/ytmusic-zig).