ZON to Zig struct

Paste a ZON file and zigshape writes the Zig type that std.zon.parse reads it into. Enum literals like .info become a Zig enum, so the struct stays typed end to end.

Target

API responseSmallest int widths from observed range; auto enum suggestion; missing/null become optional.

.{
    .name = "invoice-worker",
    .log_level = .info,
    .concurrency = 4,
    .queues = .{ "invoices", "receipts" },
    .database = .{ .host = "localhost", .port = 5432 },
}
ZON 8 lines 180 B Drop files here to add samples
Config.zig
pub const Config = struct {
    name: []const u8,
    log_level: LogLevel,
    concurrency: u8,
    queues: []const []const u8,
    database: Database,
};

pub const LogLevel = enum {
    info,
};

pub const Database = struct {
    host: []const u8,
    port: u16,
};
loading zig fmt 2 structs · 1 enum · 7 fields 16 lines

Field decisions

Why each field got its type. Click a row to see it in the input; edit to override.

struct Config $ 5 fields
enum LogLevel $.log_level 1 variant
struct Database $.database 2 fields

How ZON maps to Zig

  • .{ .field = value } becomes a struct, .{ a, b } a slice.
  • Enum literals become an enum whose variants keep their exact spelling.
  • Hex, octal and binary integers, character literals and \\ multiline strings are all understood.
  • With the serde.zig target, zigshape warns about comments, non-decimal integers and multiline strings, which serde.zig 1.2.3's ZON reader rejects.

Questions

How do I parse ZON at runtime?
Call std.zon.parse.fromSlice with the generated type. Its options changed between Zig releases, so check the signature for your version.
Can I generate types for build.zig.zon?
Yes. Paste it as is; .name = .my_package becomes an enum and .dependencies a nested struct.