{"id":15140969,"url":"https://github.com/pwbh/ymlz","last_synced_at":"2025-10-23T18:30:23.208Z","repository":{"id":254228319,"uuid":"841125766","full_name":"pwbh/ymlz","owner":"pwbh","description":"Small and convenient YAML parser for Zig","archived":false,"fork":false,"pushed_at":"2025-01-16T22:46:30.000Z","size":95,"stargazers_count":33,"open_issues_count":2,"forks_count":6,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-01-30T20:05:54.176Z","etag":null,"topics":["yaml-parser","zig","zig-library","zig-package"],"latest_commit_sha":null,"homepage":"","language":"Zig","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/pwbh.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","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":"2024-08-11T18:01:10.000Z","updated_at":"2025-01-26T13:59:01.000Z","dependencies_parsed_at":"2024-11-20T07:37:13.997Z","dependency_job_id":null,"html_url":"https://github.com/pwbh/ymlz","commit_stats":{"total_commits":90,"total_committers":4,"mean_commits":22.5,"dds":0.1777777777777778,"last_synced_commit":"2b4e071c57f8d2b60a7758199d9e5bc3dd58bc67"},"previous_names":["pwbh/ymlz"],"tags_count":14,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pwbh%2Fymlz","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pwbh%2Fymlz/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pwbh%2Fymlz/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pwbh%2Fymlz/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/pwbh","download_url":"https://codeload.github.com/pwbh/ymlz/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":237869144,"owners_count":19379274,"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":["yaml-parser","zig","zig-library","zig-package"],"created_at":"2024-09-26T08:42:50.102Z","updated_at":"2025-10-23T18:30:23.203Z","avatar_url":"https://github.com/pwbh.png","language":"Zig","funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003ch1 align=\"center\"\u003e\n  \u003cimg src=\"https://raw.githubusercontent.com/pwbh/ymlz/ea6e6bf43dbe40edd66b46fc32be714546d38c6b/imgs/logo.svg\" alt=\"ymlz\" width=\"1007\"\u003e\n\u003c/h1\u003e\n\n\u003ch4 align=\"center\"\u003eSmall and convenient \u003ca href=\"https://en.wikipedia.org/wiki/YAML\" target=\"_blank\"\u003eYAML\u003c/a\u003e parser\u003c/h4\u003e\n\n\u003cp align=\"center\"\u003e\n  \u003ca href=\"#key-features\"\u003eKey Features\u003c/a\u003e •\n  \u003ca href=\"#how-to-use\"\u003eHow To Use\u003c/a\u003e •\n  \u003ca href=\"#support\"\u003eSupport\u003c/a\u003e •\n  \u003ca href=\"#contribution\"\u003eContribution\u003c/a\u003e •\n  \u003ca href=\"#license\"\u003eLicense\u003c/a\u003e\n\u003c/p\u003e\n\n## Key Features\n\n- Simple and straightforward to use thanks to built-in [reflections](https://ziglang.org/documentation/master/#Function-Reflection).\n- Just define a struct, load a yml into it, and access your fields.\n- Supports recursive struct.\n- Deinitialization is handled for you, just call `deinit()` and you are done.\n- Fields are automatically parsed based on field type.\n- Ability to parse fields optionally.\n\n## How To Use\n\nEasiest way to use ymlz is to fetch it via `zig fetch`, **make sure to provide it the url of latest released version as the argument**.\n\nSee an example below.\n\n```bash\nzig fetch --save https://github.com/pwbh/ymlz/archive/refs/tags/0.5.0.tar.gz\n```\n\nNow in your `build.zig` we need to import ymlz as a module the following way:\n\n```zig\npub fn build(b: *std.Build) void {\n    const exe = b.addExecutable(.{ ... });\n\n    const ymlz = b.dependency(\"ymlz\", .{});\n    exe.root_module.addImport(\"ymlz\", ymlz.module(\"root\"));\n}\n```\n\n### Parsing YAML from file\n\nWe can utilize `loadFile` which expects the absolute path to your YAML file, I will be loading the following YAML file located in the root of my project under the name `file.yml`:\n\n```yml\nfirst: 500\nsecond: -3\nname: just testing strings overhere\nfourth: 142.241\nfoods:\n  - Apple\n  - Orange\n  - Strawberry\n  - Mango\ninner:\n  sd: 12\n  k: 2\n  l: hello world\n  another:\n    new: 1\n    stringed: its just a string\n```\n\nmain.zig:\n\n```zig\n/// Usage\n/// zig build run -- ./file.yml\nconst std = @import(\"std\");\n\nconst Ymlz = @import(\"ymlz\").Ymlz;\n\n// Notice how simple it is to define a struct that is one-to-one\n// to the yaml file structure\nconst Tester = struct {\n    first: i32,\n    second: i64,\n    name: []const u8,\n    fourth: f32,\n    foods: [][]const u8,\n    inner: struct {\n        sd: i32,\n        k: u8,\n        l: []const u8,\n        another: struct {\n            new: f32,\n            stringed: []const u8,\n        },\n    },\n};\n\npub fn main() !void {\n    var gpa = std.heap.GeneralPurposeAllocator(.{}){};\n    const allocator = gpa.allocator();\n    defer _ = gpa.deinit();\n\n    const args = try std.process.argsAlloc(allocator);\n    defer std.process.argsFree(allocator, args);\n\n    if (args.len \u003c 2) {\n        return error.NoPathArgument;\n    }\n\n\n    const yml_location = args[1];\n\n    const yml_path = try std.fs.cwd().realpathAlloc(\n        allocator,\n        yml_location,\n    );\n    defer allocator.free(yml_path);\n\n    var ymlz = try Ymlz(Tester).init(allocator);\n    const result = try ymlz.loadFile(yml_path);\n    defer ymlz.deinit(result);\n\n    // We can print and see that all the fields have been loaded\n    std.debug.print(\"Tester: {any}\\n\", .{result});\n    // Lets try accessing the first field and printing it\n    std.debug.print(\"First: {}\\n\", .{result.first});\n    // same goes for the array that we've defined `foods`\n    for (result.foods) |food| {\n        std.debug.print(\"{s}\", .{food});\n    }\n}\n```\n\n### Parsing YAML from bytes\n\nParsing YAML file using generic `u8` slice for the sake of our example, lets parse a small YAML inlined in to some variable that contains our YAML in `[]const u8`.\n\n```zig\nconst std = @import(\"std\");\n\nconst Ymlz = @import(\"root.zig\").Ymlz;\n\npub fn main() !void {\n    var gpa = std.heap.GeneralPurposeAllocator(.{}){};\n    const allocator = gpa.allocator();\n    defer _ = gpa.deinit();\n\n    const yaml_content =\n        \\\\first: 500\n        \\\\second: -3\n        \\\\name: just testing strings overhere # just a comment\n        \\\\fourth: 142.241\n        \\\\# comment in between lines\n        \\\\foods:\n        \\\\  - Apple\n        \\\\  - Orange\n        \\\\  - Strawberry\n        \\\\  - Mango\n        \\\\inner:\n        \\\\  abcd: 12\n        \\\\  k: 2\n        \\\\  l: hello world                 # comment somewhere\n        \\\\  another:\n        \\\\    new: 1\n        \\\\    stringed: its just a string\n    ;\n\n    const Experiment = struct {\n        first: i32,\n        second: i64,\n        name: []const u8,\n        fourth: f32,\n        foods: [][]const u8,\n        inner: struct {\n            abcd: i32,\n            k: u8,\n            l: []const u8,\n            another: struct {\n                new: f32,\n                stringed: []const u8,\n            },\n        },\n    };\n\n    var ymlz = try Ymlz(Experiment).init(allocator);\n    const result = try ymlz.loadRaw(yaml_content);\n    defer ymlz.deinit(result);\n\n    std.debug.print(\"Experiment.first: {}\\n\", .{result.first});\n}\n\n```\n\n### Parsing by providing a custom std.io.AnyReader\n\nIt's possible to pass your own implementation of the std.io.AnyReader interface to ymlz using `loadReader` which is used internally for both `loadFile` and `loadRaw`. See [internal implementation](https://github.com/pwbh/ymlz/blob/master/src/root.zig#L64) for reference.\n\n## Contribution\n\nYou are more then welcomed to submit a PR, ymlz codebase is still pretty small and it should be relatively simple to get into it, if you have any questions regarding the project or you just need assist starting out, open an issue.\n\n## Support\n\nIf you find a bug please [submit new issue](https://github.com/pwbh/ymlz/issues/new) and I will try to address it in my free time. I do however want to note that this project is used in my bigger project, so any bugs I find, I fix without reporting them as an issue, so some issues that may have been reported have beeen fixed without me seeing them.\n\n## License\n\nApache License 2.0. Can be found under the [LICENSE](https://github.com/pwbh/ymlz/blob/master/LICENSE).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpwbh%2Fymlz","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpwbh%2Fymlz","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpwbh%2Fymlz/lists"}