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.

Target

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}
NDJSON 4 lines 156 B Drop files here to add samples
Event.zig
pub const Event = struct {
    level: []const u8,
    msg: []const u8,
    ts: u32,
    ms: ?u16 = null,
};
loading zig fmt 1 struct · 4 fields 6 lines

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 StreamingDeserializer handles 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 use serde.helpers.StreamingDeserializer(Event) with a reader.