{"id":13710164,"url":"https://github.com/mattyhall/tomlz","last_synced_at":"2025-10-29T02:55:21.906Z","repository":{"id":72275107,"uuid":"562290198","full_name":"mattyhall/tomlz","owner":"mattyhall","description":"A well-tested TOML parsing library for Zig","archived":false,"fork":false,"pushed_at":"2024-06-19T17:20:48.000Z","size":176,"stargazers_count":21,"open_issues_count":4,"forks_count":4,"subscribers_count":2,"default_branch":"main","last_synced_at":"2024-08-03T23:17:58.434Z","etag":null,"topics":["parsing","toml","zig"],"latest_commit_sha":null,"homepage":"","language":"Zig","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/mattyhall.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2022-11-05T21:53:44.000Z","updated_at":"2024-06-19T17:20:52.000Z","dependencies_parsed_at":null,"dependency_job_id":"5aaef293-0d6e-4d77-9e02-234ac42b006b","html_url":"https://github.com/mattyhall/tomlz","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mattyhall%2Ftomlz","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mattyhall%2Ftomlz/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mattyhall%2Ftomlz/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mattyhall%2Ftomlz/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mattyhall","download_url":"https://codeload.github.com/mattyhall/tomlz/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":224521594,"owners_count":17325262,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["parsing","toml","zig"],"created_at":"2024-08-02T23:00:52.593Z","updated_at":"2025-10-29T02:55:16.871Z","avatar_url":"https://github.com/mattyhall.png","language":"Zig","funding_links":[],"categories":["Language Essentials"],"sub_categories":["File Format Processing"],"readme":"# tomlz\n\nA TOML parser for Zig targeting TOML v1.0.0, an easy API and safety.\nAlso supports encoding/serializing values(implemented by @0x5a4)!\n\n```zig\nconst std = @import(\"std\")\nconst tomlz = @import(\"tomlz\")\n\nvar gpa = std.heap.page_allocator;\nvar table = try tomlz.parse(gpa,\n    \\\\foo = 1\n    \\\\bar = 2\n);\ndefer table.deinit(gpa);\n\ntable.getInteger(\"foo\").?; // 1\n\n\n// --- or ---\nconst S = struct { foo: i64, bar: i64 };\nconst s = try tomlz.decode(S, gpa,\n  \\\\foo = 1\n  \\\\bar = 2\n);\n\n// serialize a value like this (also see the examples)\ntry tomlz.serialize(\n    gpa,\n    std.io.getStdout.writer()\n    s,\n);\n// foo = 1\n// bar = 2\n```\n\n## Current status\n\nAll types other than datetimes are supported. We pass 321/334 of the\n[toml tests](https://github.com/BurntSushi/toml-test) 11 of those are due to not\nhaving datetime support and the other two are minor lexing issues (allowing\nwhitespace between the square brackets of an array header).\n\nWe allow both parsing into a special TOML type, a `Table`, but also support\ndecoding into a struct directly - including types that must be allocated like\narrays and strings.\n\nThe Serializer allows encoding every kind of zig type, overwriting it's default behaviour\nby implementing a function called `tomlzSerialize`, has the option to work\nwithout an allocator and can therefore even work at `comptime`!\nNote that for some types like `std.HashMap` its not possible to just encode\nall their fields, so custom logic is needed. We can't provide this, but it's not\ntoo difficult to implement it yourself(See examples).\n\n## Installation\n\ntomlz supports being included as a module.\n\nCreate a file called `build.zig.zon` if you do not already have one, and add `tomlz` as a dependency\n\n```\n.{\n    .name = \"myproject\",\n    .version = \"0.1.0\",\n    .dependencies = .{\n        .tomlz = .{\n            .url = \"https://github.com/mattyhall/tomlz/archive/\u003ccommit-hash\u003e.tar.gz\",\n            .hash = \"12206cf9e90462ee6e14f593ea6e0802b9fe434429ba10992a1451e32900f741005c\",\n        },\n    }\n}\n```\n\nYou'll have to replace the `\u003ccommit-hash\u003e` part with an actual, recent commit-hash.\nThe hash also needs changing, but `zig build` will complain and give you the correct one.\n\nIn your `build.zig` file create and use the dependency\n\n```\npub fn build(b: *std.Build) void {\n    // ... setup ...\n\n    const tomlz = b.dependency(\"tomlz\", .{\n        .target = target,\n        .optimize = optimize,\n    });\n\n    // add the tomlz module\n    exe.root_module.addImport(\"tomlz\", tomlz.module(\"tomlz\"));\n\n    // .. continue ...\n}\n```\n\n## Usage\n\n### Table\n\nWe currently provide a single entry point for parsing which returns a toml\n`Table` type. This type has helper methods for getting values out:\n\n```zig\nconst std = @import(\"std\");\nconst tomlz = @import(\"tomlz\");\n\nvar gpa = std.heap.page_allocator;\nvar table = try tomlz.parse(gpa,\n    \\\\int = 1\n    \\\\float = 2.0\n    \\\\boolean = true\n    \\\\string = \"hello, world\"\n    \\\\array = [1, 2, 3]\n    \\\\table = { subvalue = 1, we.can.nest.keys = 2 }\n);\ndefer table.deinit(gpa);\n\ntable.getInteger(\"int\");\ntable.getFloat(\"float\");\ntable.getBool(\"boolean\");\ntable.getString(\"string\");\ntable.getArray(\"array\");\ntable.getTable(\"table\");\n```\n\nA simple example is\n[provided](https://github.com/mattyhall/tomlz/tree/main/examples/simple/).\n\n### Decode\n\n```zig\nconst std = @import(\"std\");\nconst tomlz = @import(\"tomlz\");\n\nvar gpa = std.heap.page_allocator;\nconst TripleCrowns = struct { worlds: i64, masters: i64, uks: i64 };\n\nconst Player = struct {\n    name: []const u8,\n    age: i64,\n    hobbies: []const []const u8,\n    triplecrowns: TripleCrowns,\n\n    const Self = @This();\n\n    pub fn deinit(self: *Self, gpa: std.mem.Allocator) void {\n        gpa.free(self.name);\n\n        for (self.hobbies) |hobby| {\n            gpa.free(hobby);\n        }\n        gpa.free(self.hobbies);\n    }\n};\n\nconst Game = struct {\n    name: []const u8,\n    goat: Player,\n\n    const Self = @This();\n\n    pub fn deinit(self: *Self, gpa: std.mem.Allocator) void {\n        gpa.free(self.name);\n        self.goat.deinit(gpa);\n    }\n};\n\nvar s = try tomlz.decode(Game, gpa,\n    \\\\name = \"snooker\"\n    \\\\\n    \\\\[goat]\n    \\\\name = \"Ronnie o' Sullivan\"\n    \\\\age = 46 # as of Nov 2022\n    \\\\hobbies = [\"running\", \"hustling at pool\"]\n    \\\\\n    \\\\[goat.triplecrowns]\n    \\\\worlds = 7\n    \\\\masters = 7\n    \\\\uks = 7\n);\ndefer s.deinit(gpa);\n```\n\n### Encode\n\nHave a look at [the example](examples/serialize/src/main.zig).\n\n## Goals and non-goals\n\nGoals and non-goals are subject to change based on how the project is used and\nmy own time constraints. If you feel a goal or non-goal isn't quite right please\nopen an issue and we can discuss it.\n\n### Goals\n\n- TOML v1.0.0. The datetime portion of this is probably going to be\n  unachievable until Zig gets a good standard library type for it or a library\n  gets dominance. Other than that however we should pass all the\n  [tests](https://github.com/BurntSushi/toml-test)\n- A nice API. Getting values from the `Value` type should be painless as\n  possible and we should also provide deserialising a `Table` into a struct,\n  similarly to how `std.json` does it\n- Easy installation. We should try to make using the library as a vendored\n  dependency and as a package - on e.g. [gyro](https://github.com/mattnite/gyro)\n  \\- as easy as possible\n- Safety. The parser should never crash no matter the input. To achieve this we\n  should run fuzzing against it\n- Support Zig master and the latest tagged release until Zig v1.0. This will be\n  done by having the main branch track Zig master and a branch for each Zig\n  release. Any improvements should be backported to the most recent release\n  branch\n- Good error messages\n\n### Non-goals\n\n- Super duper performance. We want to be as performant as possible without\n  making the code harder to read. It is unlikely that parsing a TOML file is\n  going to be the bottleneck in your application so \"good\" performance should be\n  sufficient\n- Previous versions of TOML\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmattyhall%2Ftomlz","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmattyhall%2Ftomlz","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmattyhall%2Ftomlz/lists"}