This lib generates zig code from arbitrary json data which can then parse it.
The schema gen is in python. Maybe I’ll port to zig soon. But here’s how it works. I’m using the build system to
generate a zig file by running the python code
create a module from the generated file
import the module in main.zig
parse the original json file and show its cache path
Hopefully this makes it really quick to generate a zig struct for parsing json!
Motivation
When you need to parse arbitrary json in zig, you usually pass std.json.Value to one of the parse() methods. This is convenient but is generally slower and allocates more memory than passing a concrete type.
Also, std.json.Value can be a little akward at times. Here is how it looks to access data from the github api
This library was developed after struggling with code generated by https://aerth.github.io/json-to-zig/. Hopefully std.json gets diagnostics soon cause it can be difficult to tell which fields were causing parse errors.
its pretty much a clone of @aerth’s json-to-zig but mostly from scratch and does the conversion in wasm
this required these changes since last time:
ported the python script to zig
made a wasm build step
made a simple web app which calls the wasm module to generate the zig code
the current wasm blob is 71kb release small. i tried adding a minimal panic handler but that didn’t seem to change the size at all. let me know if you have any ideas to make it smaller.