{"id":13710135,"url":"https://github.com/kubkon/zig-yaml","last_synced_at":"2025-05-16T18:05:46.444Z","repository":{"id":38440120,"uuid":"372617322","full_name":"kubkon/zig-yaml","owner":"kubkon","description":"YAML parser for Zig","archived":false,"fork":false,"pushed_at":"2025-03-18T15:57:53.000Z","size":295,"stargazers_count":213,"open_issues_count":10,"forks_count":45,"subscribers_count":4,"default_branch":"main","last_synced_at":"2025-04-03T19:15:42.146Z","etag":null,"topics":["yaml","zig","zig-library"],"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/kubkon.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":".github/FUNDING.yml","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},"funding":{"github":["kubkon"],"patreon":null,"open_collective":null,"ko_fi":null,"tidelift":null,"community_bridge":null,"liberapay":null,"issuehunt":null,"otechie":null,"lfx_crowdfunding":null,"custom":null}},"created_at":"2021-05-31T20:06:47.000Z","updated_at":"2025-04-01T05:41:15.000Z","dependencies_parsed_at":"2024-01-15T21:26:00.082Z","dependency_job_id":"ab450add-9e01-4971-9b85-bdd9d7f521ff","html_url":"https://github.com/kubkon/zig-yaml","commit_stats":{"total_commits":116,"total_committers":10,"mean_commits":11.6,"dds":0.1637931034482759,"last_synced_commit":"bd6a1847857b9bcf45aa9b5328ab7bb067231e0d"},"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kubkon%2Fzig-yaml","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kubkon%2Fzig-yaml/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kubkon%2Fzig-yaml/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kubkon%2Fzig-yaml/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/kubkon","download_url":"https://codeload.github.com/kubkon/zig-yaml/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248606859,"owners_count":21132428,"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","zig","zig-library"],"created_at":"2024-08-02T23:00:52.217Z","updated_at":"2025-04-12T17:37:54.501Z","avatar_url":"https://github.com/kubkon.png","language":"Zig","funding_links":["https://github.com/sponsors/kubkon"],"categories":["Applications","Zig","Language Essentials"],"sub_categories":["File Format Processing"],"readme":"# zig-yaml\n\nYAML parser for Zig\n\n## What is it?\n\nThis lib is meant to serve as a basic (or maybe not?) YAML parser for Zig. It will strive to be YAML 1.2 compatible\nbut one step at a time.\n\nThis is very much a work-in-progress, so expect things to break on a regular basis. Oh, I'd love to get the\ncommunity involved in helping out with this btw! Feel free to fork and submit patches, enhancements, and of course\nissues.\n\n\n## Basic installation\n\nThe library can be installed using the Zig tools. First, you need to fetch the required release of the library into your project. \n```\nzig fetch --save https://github.com/kubkon/zig-yaml/archive/refs/tags/[RELEASE_VERSION].tar.gz\n```\n\nIt's more convenient to save the library with a desired name, for example, like this (assuming you are targeting latest release of Zig):\n```\nzig fetch --save=yaml https://github.com/kubkon/zig-yaml/archive/refs/tags/0.1.1.tar.gz\n```\n\nAnd then add those lines to your project's `build.zig` file:\n```\n// add that code after \"b.installArtifact(exe)\" line\nconst yaml = b.dependency(\"yaml\", .{\n  .target = target,\n  .optimize = optimize,\n});\nexe.root_module.addImport(\"yaml\", yaml.module(\"yaml\"));\n```\n\nAfter that, you can simply import the zig-yaml library in your project's code by using `const yaml = @import(\"yaml\");`.\n\nFor zig-0.14, please use any release after `0.1.0`. For pre-zig-0.14 (e.g., zig-0.13), use `0.0.1`.\n\n## Basic usage\n\nThe parser currently understands a few YAML primitives such as:\n* explicit documents (`---`, `...`)\n* mappings (`:`)\n* sequences (`-`, `[`, `]`)\n\nIn fact, if you head over to `examples/` dir, you will find YAML examples that have been tested against this\nparser. You can also have a look at end-to-end test inputs in `test/` directory.\n\nIf you want to use the parser as a library, add it as a package the usual way, and then:\n\n```zig\nconst std = @import(\"std\");\nconst Yaml = @import(\"yaml\").Yaml;\nconst gpa = std.testing.allocator;\n\nconst source =\n    \\\\names: [ John Doe, MacIntosh, Jane Austin ]\n    \\\\numbers:\n    \\\\  - 10\n    \\\\  - -8\n    \\\\  - 6\n    \\\\nested:\n    \\\\  some: one\n    \\\\  wick: john doe\n    \\\\finally: [ 8.17,\n    \\\\           19.78      , 17 ,\n    \\\\           21 ]\n;\n\nvar yaml: Yaml = .{ .source = source };\ndefer yaml.deinit(gpa);\n```\n\n1. For untyped, raw representation of YAML, use `Yaml.load`:\n\n```zig\ntry yaml.load(gpa, source);\n\ntry std.testing.expectEqual(untyped.docs.items.len, 1);\n\nconst map = untyped.docs.items[0].map;\ntry std.testing.expect(map.contains(\"names\"));\ntry std.testing.expectEqual(map.get(\"names\").?.list.len, 3);\n```\n\n2. For typed representation of YAML, use `Yaml.parse`:\n\n```zig\nconst Simple = struct {\n    names: []const []const u8,\n    numbers: []const i16,\n    nested: struct {\n        some: []const u8,\n        wick: []const u8,\n    },\n    finally: [4]f16,\n};\n\nvar arena = std.heap.ArenaAllocator.init(gpa);\ndefer arena.deinit();\n\nconst simple = try yaml.parse(arena.allocator(), Simple);\ntry std.testing.expectEqual(simple.names.len, 3);\n```\n\n3. To convert `Yaml` structure back into text representation, use `Yaml.stringify`:\n\n```zig\ntry yaml.stringify(std.io.getStdOut().writer());\n```\n\nwhich should write the following output to standard output when run:\n\n```sh\nnames: [ John Doe, MacIntosh, Jane Austin  ]\nnumbers: [ 10, -8, 6  ]\nnested:\n    some: one\n    wick: john doe\nfinally: [ 8.17, 19.78, 17, 21  ]\n```\n\n### Error handling\n\nThe library currently reports user-friendly, more informative parsing errors only which are stored out-of-band.\nThey can be accessed via `Yaml.parse_errors: std.zig.ErrorBundle`, but typically you would only hook them up to\nyour error reporting setup.\n\nFor example, `example/yaml.zig` binary does it like so:\n\n```zig\nvar yaml: Yaml = .{ .source = source };\ndefer yaml.deinit(allocator);\n\nyaml.load(allocator) catch |err| switch (err) {\n    error.ParseFailure =\u003e {\n        assert(yaml.parse_errors.errorMessageCount() \u003e 0);\n        yaml.parse_errors.renderToStdErr(.{ .ttyconf = std.io.tty.detectConfig(std.io.getStdErr()) });\n        return error.ParseFailure;\n    },\n    else =\u003e return err,\n};\n```\n\n## Running YAML spec test suite\n\nRemember to clone the repo with submodules first\n\n```sh\ngit clone --recurse-submodules\n```\n\nThen, you can run the test suite as follows\n\n```sh\nzig build test -Denable-spec-tests\n```\n\nSee also [issue #48](https://github.com/kubkon/zig-yaml/issues/48) for a meta issue tracking failing spec tests.\n\nAny test that you think of working on and would like to include in the spec tests (that was previously skipped), can be removed from the skipped tests lists in https://github.com/kubkon/zig-yaml/blob/b3cc3a3319ab40fa466a4d5e9c8483267e6ffbee/test/spec.zig#L239-L562\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkubkon%2Fzig-yaml","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkubkon%2Fzig-yaml","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkubkon%2Fzig-yaml/lists"}