NDJSON to Zig struct
Paste newline-delimited JSON such as log lines or event streams. Every line counts as a sample, so one struct covers all of them.
API responseSmallest int widths from observed range; auto enum suggestion; missing/null become optional.
{"level":"info","msg":"started","ts":1767225600}
{"level":"warn","msg":"slow query","ts":1767225601,"ms":840}
{"level":"info","msg":"done","ts":1767225602}
Event.zig pub const Event = struct {
level: []const u8,
msg: []const u8,
ts: u32,
ms: ?u16 = null,
};
Field decisions
Why each field got its type. Click a row to see it in the input; edit to override.
struct Event $ 4 fields
How lines become one struct
- Each line is parsed and observed on its own.
- Keys present on only some lines become
?T = null. - The parse helper reads one line; serde.zig's
StreamingDeserializerhandles whole streams.
Questions
- How do I parse NDJSON in Zig?
- Split the input on newlines and parse each line with
std.json.parseFromSlice(Event, allocator, line, .{}), or useserde.helpers.StreamingDeserializer(Event)with a reader.