A lightweight JSON parser written in Zig that supports JSONPath queries. This is my first Zig project, created to learn the language and explore its capabilities.
- Parse JSON strings into a queryable structure
- Support for JSONPath syntax queries
- Handle nested objects and arrays
- Zero dependencies beyond Zig standard library
const json_string =
\\{ "store": { "book": [
\\ { "title": "Book 1" },
\\ { "title": "Book 2" },
\\ { "title": "Book 3" },
\\ { "title": "Book 4" }
\\] } }
;
const allocator = std.heap.page_allocator;
var jason = Jason.init(allocator, json_string);
const queried = try jason.query("$.store.book[3].title");
jason.printValue(queried); // Outputs: "Book 4"
The parser supports JSONPath queries similar to popular implementations. For example:
// Access nested objects
"$.store.book[2].title"
// Access array elements
"$.item1[0]"
// Access nested object properties
"$.item1[2].some.thing"
This parser is implemented with simplicity in mind while maintaining functionality. It follows the JSON specification as defined in RFC 4627.
The project draws inspiration from several sources:
This is an active learning project. The code is functional but may not follow Zig best practices in all areas as I'm still learning the language. Feedback and suggestions for improvement are welcome!
- Error handling could be more robust
- Memory management might need optimization
- Code structure could be more idiomatic Zig
- Test coverage could be expanded
Since this is a learning project, I welcome all forms of feedback:
- Open issues for code improvements or suggestions
- Share Zig best practices and idioms
- Point out areas where the code could be more efficient
- Suggest additional features or improvements
As my first Zig project, this has been a valuable learning experience. I'm actively working on improving the code quality and learning better Zig patterns. Some key learnings so far:
- Working with Zig's memory allocator system
- Understanding Zig's error handling approach
- Managing complex data structures in Zig
For those interested in similar projects or learning Zig: