{"id":14985590,"url":"https://github.com/jpsim/yams","last_synced_at":"2025-05-14T03:08:35.495Z","repository":{"id":37678088,"uuid":"74237729","full_name":"jpsim/Yams","owner":"jpsim","description":"A Sweet and Swifty YAML parser.","archived":false,"fork":false,"pushed_at":"2025-04-29T11:09:33.000Z","size":23344,"stargazers_count":1156,"open_issues_count":42,"forks_count":152,"subscribers_count":22,"default_branch":"main","last_synced_at":"2025-05-11T03:02:46.361Z","etag":null,"topics":["ios","libyaml","linux","macos","swift","yaml"],"latest_commit_sha":null,"homepage":"https://jpsim.com/Yams","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/jpsim.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":"CONTRIBUTING.md","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}},"created_at":"2016-11-19T21:55:12.000Z","updated_at":"2025-05-10T11:50:17.000Z","dependencies_parsed_at":"2023-10-16T10:56:08.697Z","dependency_job_id":"311b22f6-db38-49dc-bb05-56b31dc6b14c","html_url":"https://github.com/jpsim/Yams","commit_stats":{"total_commits":795,"total_committers":37,"mean_commits":"21.486486486486488","dds":"0.42515723270440253","last_synced_commit":"53d8b3b730635b68a0b2fc720643e8cea4f6b6e2"},"previous_names":[],"tags_count":47,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jpsim%2FYams","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jpsim%2FYams/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jpsim%2FYams/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jpsim%2FYams/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/jpsim","download_url":"https://codeload.github.com/jpsim/Yams/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254048974,"owners_count":22005984,"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":["ios","libyaml","linux","macos","swift","yaml"],"created_at":"2024-09-24T14:11:17.701Z","updated_at":"2025-05-14T03:08:35.451Z","avatar_url":"https://github.com/jpsim.png","language":"Swift","readme":"# Yams\n\n![Yams](https://raw.githubusercontent.com/jpsim/Yams/main/yams.jpg)\n\nA sweet and swifty [YAML](http://yaml.org/) parser built on\n[LibYAML](https://github.com/yaml/libyaml).\n\n[![SwiftPM](https://github.com/jpsim/Yams/workflows/SwiftPM/badge.svg)](https://github.com/jpsim/Yams/actions?query=workflow%3ASwiftPM)\n[![xcodebuild](https://github.com/jpsim/Yams/workflows/xcodebuild/badge.svg)](https://github.com/jpsim/Yams/actions?query=workflow%3Axcodebuild)\n[![pod lib lint](https://github.com/jpsim/Yams/workflows/pod%20lib%20lint/badge.svg)](https://github.com/jpsim/Yams/actions?query=workflow%3A%22pod+lib+lint%22)\n[![Nightly](https://github.com/jpsim/Yams/workflows/Nightly/badge.svg)](https://github.com/jpsim/Yams/actions?query=workflow%3ANightly)\n[![codecov](https://codecov.io/gh/jpsim/Yams/branch/main/graph/badge.svg)](https://codecov.io/gh/jpsim/Yams)\n\n## Installation\n\nBuilding Yams requires Xcode 14.0+ or a Swift 5.7+ toolchain with the\nSwift Package Manager or CMake and Ninja.\n\n### CMake\n\nCMake 3.17.2 or newer is required, along with Ninja 1.9.0 or newer.\n\nWhen building for non-Apple platforms:\n\n```\ncmake -B /path/to/build -G Ninja -S /path/to/yams -DCMAKE_BUILD_TYPE=Release -DFoundation_DIR=/path/to/foundation/build/cmake/modules\ncmake --build /path/to/build\n```\n\nTo build for Apple platforms (macOS, iOS, tvOS, watchOS), there is no\nneed to separately build Foundation because it is included as part of\nthe SDK:\n\n```\ncmake -B /path/to/build -G Ninja -S /path/to/yams -DCMAKE_BUILD_TYPE=Release\ncmake --build /path/to/build\n```\n\n### Swift Package Manager\n\nAdd `.package(url: \"https://github.com/jpsim/Yams.git\", from: \"5.1.3\")` to your\n`Package.swift` file's `dependencies`.\n\n### CocoaPods\n\nAdd `pod 'Yams'` to your `Podfile`.\n\n### Carthage\n\nAdd `github \"jpsim/Yams\"` to your `Cartfile`.\n\n### Bazel\n\nIn your WORKSPACE file\n\n```WORKSPACE\nYAMS_GIT_SHA = \"SOME_SHA\"\nhttp_archive(\n    name = \"com_github_jpsim_yams\",\n    urls = [\n        \"https://github.com/jpsim/Yams/archive/%s.zip\" % YAMS_GIT_SHA,\n    ],\n    strip_prefix = \"Yams-%s\" % YAMS_GIT_SHA,\n)\n```\n\n## Usage\n\nYams has three groups of conversion APIs:\none for use with [`Codable` types](#codable-types),\nanother for [Swift Standard Library types](#swift-standard-library-types),\nand a third one for a [Yams-native](#yamsnode) representation.\n\n#### `Codable` types\n\n- Codable is an [encoding \u0026 decoding strategy introduced in Swift 4][Codable]\n  enabling easy conversion between YAML and other Encoders like\n  [JSONEncoder][JSONEncoder] and [PropertyListEncoder][PropertyListEncoder].\n- Lowest computational overhead, equivalent to `Yams.Node`.\n- **Encoding: `YAMLEncoder.encode(_:)`**\n  Produces a YAML `String` from an instance of type conforming to `Encodable`.\n- **Decoding: `YAMLDecoder.decode(_:from:)`**\n  Decodes an instance of type conforming to `Decodable` from YAML `String` or\n  `Data`.\n\n```swift\nimport Foundation\nimport Yams\n\nstruct S: Codable {\n    var p: String\n}\n\nlet s = S(p: \"test\")\nlet encoder = YAMLEncoder()\nlet encodedYAML = try encoder.encode(s)\nencodedYAML == \"\"\"\np: test\n\n\"\"\"\nlet decoder = YAMLDecoder()\nlet decoded = try decoder.decode(S.self, from: encodedYAML)\ns.p == decoded.p\n```\n\n#### Swift Standard Library types\n\n- The type of Swift Standard Library is inferred from the contents of the\n  internal `Yams.Node` representation by matching regular expressions.\n- This method has the largest computational overhead When decoding YAML, because\n  the type inference of all objects is done up-front.\n- It may be easier to use in such a way as to handle objects created from\n  `JSONSerialization` or if the input is already standard library types\n  (`Any`, `Dictionary`, `Array`, etc.).\n- **Encoding: `Yams.dump(object:)`**\n  Produces a YAML `String` from an instance of Swift Standard Library types.\n- **Decoding: `Yams.load(yaml:)`**\n  Produces an instance of Swift Standard Library types as `Any` from YAML\n  `String`.\n\n```swift\n// [String: Any]\nlet dictionary: [String: Any] = [\"key\": \"value\"]\nlet mapYAML: String = try Yams.dump(object: dictionary)\nmapYAML == \"\"\"\nkey: value\n\n\"\"\"\nlet loadedDictionary = try Yams.load(yaml: mapYAML) as? [String: Any]\n\n// [Any]\nlet array: [Int] = [1, 2, 3]\nlet sequenceYAML: String = try Yams.dump(object: array)\nsequenceYAML == \"\"\"\n- 1\n- 2\n- 3\n\n\"\"\"\nlet loadedArray: [Int]? = try Yams.load(yaml: sequenceYAML) as? [Int]\n\n// Any\nlet string = \"string\"\nlet scalarYAML: String = try Yams.dump(object: string)\nscalarYAML == \"\"\"\nstring\n\n\"\"\"\nlet loadedString: String? = try Yams.load(yaml: scalarYAML) as? String\n```\n\n#### `Yams.Node`\n\n- Yams' native model representing [Nodes of YAML][Nodes Spec] which provides all\n  functions such as detection and customization of the YAML format.\n- Depending on how it is used, computational overhead can be minimized.\n- **Encoding: `Yams.serialize(node:)`**\n  Produces a YAML `String` from an instance of `Node`.\n- **Decoding `Yams.compose(yaml:)`**\n  Produces an instance of `Node` from YAML `String`.\n\n```swift\nvar map: Yams.Node = [\n    \"array\": [\n        1, 2, 3\n    ]\n]\nmap.mapping?.style = .flow\nmap[\"array\"]?.sequence?.style = .flow\nlet yaml = try Yams.serialize(node: map)\nyaml == \"\"\"\n{array: [1, 2, 3]}\n\n\"\"\"\nlet node = try Yams.compose(yaml: yaml)\nmap == node\n```\n\n#### Integrating with [Combine](https://developer.apple.com/documentation/combine)\n\nWhen Apple's Combine framework is available, `YAMLDecoder` conforms to the\n`TopLevelDecoder` protocol, which allows it to be used with the\n`decode(type:decoder:)` operator:\n\n```swift\nimport Combine\nimport Foundation\nimport Yams\n\nfunc fetchBook(from url: URL) -\u003e AnyPublisher\u003cBook, Error\u003e {\n    URLSession.shared.dataTaskPublisher(for: url)\n        .map(\\.data)\n        .decode(type: Book.self, decoder: YAMLDecoder())\n        .eraseToAnyPublisher()\n}\n```\n\n## License\n\nBoth Yams and libYAML are MIT licensed.\n\n[Codable]: https://developer.apple.com/documentation/foundation/archives_and_serialization/encoding_and_decoding_custom_types\n[JSONEncoder]: https://developer.apple.com/documentation/foundation/jsonencoder\n[PropertyListEncoder]: https://developer.apple.com/documentation/foundation/propertylistencoder\n[Nodes Spec]: http://www.yaml.org/spec/1.2/spec.html#id2764044\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjpsim%2Fyams","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjpsim%2Fyams","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjpsim%2Fyams/lists"}