{"id":41852699,"url":"https://github.com/mhayes853/swift-stream-parsing","last_synced_at":"2026-04-12T07:10:01.368Z","repository":{"id":334115753,"uuid":"1123082609","full_name":"mhayes853/swift-stream-parsing","owner":"mhayes853","description":"Byte-by-byte parsing in Swift.","archived":false,"fork":false,"pushed_at":"2026-02-13T05:04:26.000Z","size":14328,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2026-02-13T13:26:50.515Z","etag":null,"topics":["json","json-parser","json5","macros","parsing","swift"],"latest_commit_sha":null,"homepage":"","language":"Swift","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/mhayes853.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,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2025-12-26T06:40:23.000Z","updated_at":"2026-02-13T05:03:46.000Z","dependencies_parsed_at":null,"dependency_job_id":null,"html_url":"https://github.com/mhayes853/swift-stream-parsing","commit_stats":null,"previous_names":["mhayes853/swift-stream-parsing"],"tags_count":4,"template":false,"template_full_name":null,"purl":"pkg:github/mhayes853/swift-stream-parsing","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mhayes853%2Fswift-stream-parsing","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mhayes853%2Fswift-stream-parsing/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mhayes853%2Fswift-stream-parsing/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mhayes853%2Fswift-stream-parsing/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mhayes853","download_url":"https://codeload.github.com/mhayes853/swift-stream-parsing/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mhayes853%2Fswift-stream-parsing/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":29706569,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-02-22T05:59:28.568Z","status":"ssl_error","status_checked_at":"2026-02-22T05:58:46.208Z","response_time":110,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.6:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"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":["json","json-parser","json5","macros","parsing","swift"],"created_at":"2026-01-25T10:33:02.926Z","updated_at":"2026-04-12T07:10:01.352Z","avatar_url":"https://github.com/mhayes853.png","language":"Swift","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Swift Stream Parsing\n\n[![CI](https://github.com/mhayes853/swift-stream-parsing/actions/workflows/ci.yml/badge.svg)](https://github.com/mhayes853/swift-stream-parsing/actions/workflows/ci.yml)\n[![](https://img.shields.io/endpoint?url=https%3A%2F%2Fswiftpackageindex.com%2Fapi%2Fpackages%2Fmhayes853%2Fswift-stream-parsing%2Fbadge%3Ftype%3Dswift-versions)](https://swiftpackageindex.com/mhayes853/swift-stream-parsing)\n[![](https://img.shields.io/endpoint?url=https%3A%2F%2Fswiftpackageindex.com%2Fapi%2Fpackages%2Fmhayes853%2Fswift-stream-parsing%2Fbadge%3Ftype%3Dplatforms)](https://swiftpackageindex.com/mhayes853/swift-stream-parsing)\n\nA Swift toolkit for type-safe incremental parsing.\n\n## Overview\n\n`JSONDecoder` and `Codable` are powerful tools when you need to decode structured JSON bytes, however both of those tools require the entire data payload to be present at decode time.\n\nThis is especially problematic for applications such as streaming structured data from LLMs. For example, the FoundationModels framework has its own set of interfaces for incrementally streaming structured data.\n\nThis library offers a dedicated interface for incremental parsing with built-in JSON support.\n\n## Quick Start\n\nFirst, you create a struct that uses the `@StreamParseable` macro, and then you can begin parsing!\n\n```swift\nimport StreamParsing\n\n@StreamParseable\nstruct Profile {\n  var id: Int\n  var name: String\n  var isActive: Bool\n}\n\nlet json = \"\"\"\n{\n  \"id\": 4,\n  \"name\": \"Blob\",\n  \"isActive\": true\n}\n\"\"\"\n\nlet partials: [Profile.Partial] = try json.utf8\n  .partials(of: Profile.Partial.self, from: .json())\n\nfor partial in partials {\n  print(partial)\n}\n\n// Prints:\n// Profile.Partial(id: nil, name: nil, isActive: nil)\n// ...\n// Profile.Partial(id: Optional(4), name: nil, isActive: nil)\n// ...\n// Profile.Partial(id: Optional(4), name: Optional(\"B\"), isActive: nil)\n// Profile.Partial(id: Optional(4), name: Optional(\"Bl\"), isActive: nil)\n// Profile.Partial(id: Optional(4), name: Optional(\"Blo\"), isActive: nil)\n// Profile.Partial(id: Optional(4), name: Optional(\"Blob\"), isActive: nil)\n// ...\n// Profile.Partial(id: Optional(4), name: Optional(\"Blob\"), isActive: Optional(true))\n```\n\nThe `@StreamParseable` macro generates a `Partial` struct with all optional members. \n\n```swift\nextension Profile: StreamParsingCore.StreamParseable {\n  struct Partial: StreamParsingCore.StreamParseableValue,\n    StreamParsingCore.StreamParseable {\n    typealias Partial = Self\n\n    var id: Int.Partial?\n    var name: String.Partial?\n    var isActive: Bool.Partial?\n\n    init(\n      id: Int.Partial? = nil,\n      name: String.Partial? = nil,\n      isActive: Bool.Partial? = nil\n    ) {\n      self.id = id\n      self.name = name\n      self.isActive = isActive\n    }\n\n    static func initialParseableValue() -\u003e Self {\n      Self()\n    }\n\n    static func registerHandlers(\n      in handlers: inout some StreamParsingCore.StreamParserHandlers\u003cSelf\u003e\n    ) {\n      handlers.registerKeyedHandler(forKey: \"id\", \\.id)\n      handlers.registerKeyedHandler(forKey: \"name\", \\.name)\n      handlers.registerKeyedHandler(forKey: \"isActive\", \\.isActive)\n    }\n  }\n}\n```\n\nAdditionally, all stored members on an `@StreamParseable` must also conform to the `StreamParseable` protocol. Naturally, the `@StreamParseable` macro handles the protocol conformance for you.\n\nYou can also parse partials from an AsyncSequence of bytes or byte chunks.\n\n```swift\nstruct AsyncJSONBytesSequence: AsyncSequence {\n  typealias Element = UInt8\n  \n  // ...\n}\n\nlet partials = AsyncJSONBytesSequence(...)\n  .partials(of: Profile.Partial.self, from: .json())\nfor try await profilePartial in partials {\n  print(profilePartial)\n}\n```\n\n## Parsers\n\nThe library comes with built-in JSON and YAML parsers. You can pass a custom configuration to either parser to customize key decoding behavior.\n\n### JSON\n\n```swift\nlet configuration = JSONStreamParserConfiguration(\n  syntaxOptions: [.comments, .trailingCommas],\n  keyDecodingStrategy: .convertFromSnakeCase\n)\n\nlet partials: [Profile.Partial] = try json.utf8\n  .partials(of: Profile.Partial.self, from: .json(configuration: configuration))\n```\n\n### YAML\n\n```swift\nlet yaml = \"\"\"\nid: 4\nname: Blob\nisActive: true\n\"\"\"\n\nlet partials: [Profile.Partial] = try yaml.utf8\n  .partials(of: Profile.Partial.self, from: .yaml())\n\nlet configuration = YAMLStreamParserConfiguration(\n  keyDecodingStrategy: .convertFromSnakeCase\n)\n\nlet snakeCaseYAML = \"\"\"\nid: 4\nname: Blob\nis_active: true\n\"\"\"\n\nlet partials = try snakeCaseYAML.utf8.partials(\n  of: Profile.Partial.self,\n  from: .yaml(configuration: configuration)\n)\n```\n\n## Traits\n\nWhile the core library itself has 0 dependencies, you can enable the following package traits to integrate with additional dependencies:\n- `StreamParsingSwiftCollections` interops the library with types from Swift Collections.\n- `StreamParsingFoundation` interops the library with types from Foundation (enabled by default).\n- `StreamParsingTagged` interops the library with `Tagged`.\n- `StreamParsingCoreGraphics` interops the library with CoreGraphics types (enabled by default).\n\n## Documentation\n\nThe documentation for releases and main are available here.\n* [StreamParsing (main)](https://swiftpackageindex.com/mhayes853/swift-stream-parsing/main/documentation/streamparsing/)\n* [StreamParsing (0.x.x)](https://swiftpackageindex.com/mhayes853/swift-stream-parsing/~/documentation/streamparsing/)\n* [StreamParsingCore (main)](https://swiftpackageindex.com/mhayes853/swift-stream-parsing/main/documentation/streamparsingcore/)\n* [StreamParsingCore (0.x.x)](https://swiftpackageindex.com/mhayes853/swift-stream-parsing/~/documentation/streamparsingcore/)\n\n## Installation\nYou can add Swift Stream Parsing to an Xcode project by adding it to your project as a package.\n\n\u003e [https://github.com/mhayes853/swift-stream-parsing](https://github.com/mhayes853/swift-stream-parsing)\n\n\u003e [!NOTE] \n\u003e Xcode 26.4 is required for using traits directly in Xcode projects.\n\nIf you want to use Swift Stream Parsing in a [SwiftPM](https://swift.org/package-manager/) project, it’s as simple as adding it to your `Package.swift`:\n\n```swift\ndependencies: [\n  .package(\n    url: \"https://github.com/mhayes853/swift-stream-parsing\",\n    from: \"0.5.0\",\n    // You can omit the traits if you don't need any of them.\n    traits: [\"StreamParsingSwiftCollections\"]\n  ),\n]\n```\n\n## License\n\nThis library is licensed under the MIT License. See [LICENSE](LICENSE) for details.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmhayes853%2Fswift-stream-parsing","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmhayes853%2Fswift-stream-parsing","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmhayes853%2Fswift-stream-parsing/lists"}