{"id":13465620,"url":"https://github.com/behrang/YamlSwift","last_synced_at":"2025-03-25T16:32:23.678Z","repository":{"id":21797507,"uuid":"25120032","full_name":"behrang/YamlSwift","owner":"behrang","description":"Load YAML and JSON documents using Swift","archived":false,"fork":false,"pushed_at":"2023-04-15T05:51:04.000Z","size":336,"stargazers_count":407,"open_issues_count":13,"forks_count":98,"subscribers_count":10,"default_branch":"master","last_synced_at":"2025-03-21T20:48:08.374Z","etag":null,"topics":[],"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/behrang.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}},"created_at":"2014-10-12T13:25:49.000Z","updated_at":"2025-01-14T01:41:32.000Z","dependencies_parsed_at":"2024-01-02T23:55:23.365Z","dependency_job_id":null,"html_url":"https://github.com/behrang/YamlSwift","commit_stats":{"total_commits":234,"total_committers":23,"mean_commits":"10.173913043478262","dds":0.4273504273504274,"last_synced_commit":"063286d0a66200b6ae0687c06914b19fe7c8dc83"},"previous_names":[],"tags_count":27,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/behrang%2FYamlSwift","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/behrang%2FYamlSwift/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/behrang%2FYamlSwift/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/behrang%2FYamlSwift/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/behrang","download_url":"https://codeload.github.com/behrang/YamlSwift/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245500385,"owners_count":20625569,"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":[],"created_at":"2024-07-31T15:00:32.709Z","updated_at":"2025-03-25T16:32:23.395Z","avatar_url":"https://github.com/behrang.png","language":"Swift","funding_links":[],"categories":["Libs","Swift","JSON Parse","Data Management [🔝](#readme)"],"sub_categories":["Data Management"],"readme":"# YamlSwift\n\nLoad [YAML](http://yaml.org) and [JSON](http://json.org) documents using [Swift](http://www.apple.com/swift/).\n\n`YamlSwift` parses a string of YAML document(s) (or a JSON document) and returns a `Yaml` enum value representing that string.\n\n\n\n\n\n## Install\n\nUse [Carthage](https://github.com/Carthage/Carthage) to build and install.\n\nOr use [CocoaPods](https://cocoapods.org/) :\nAdd `pod 'Yaml'` to your `Podfile` and run `pod install`.\n\nIt supports Swift Package Manager. \n\n```\n        .package(\n            url: \"https://github.com/behrang/YamlSwift.git\",\n            from: \"3.4.4\")\n\n```\n\nAnd:\n\n```\n        .target(\n            name: \"YourProject\",\n            dependencies: [\"Yaml\"]),\n```\n\n## API\n\n\n\n\n\n### import\n\nTo use it, you should import it using the following statement:\n\n```swift\nimport Yaml\n```\n\n\n\n\n\n### Yaml\n\nA Yaml value can be any of these cases:\n\n```swift\nenum Yaml {\n  case null\n  case bool(Bool)\n  case int(Int)\n  case double(Double)\n  case string(String)\n  case array([Yaml])\n  case dictionary([Yaml: Yaml])\n}\n```\n\n\n\n\n\n### Yaml.load\n\n```swift\nYaml.load (String) throws -\u003e Yaml\n```\n\nTakes a string of a YAML document and returns a `Yaml` enum.\n\n```swift\nlet value = try! Yaml.load(\"a: 1\\nb: 2\")\nprint(value[\"a\"])  // Int(1)\nprint(value[\"b\"])  // Int(2)\nprint(value[\"c\"])  // Null\n```\n\nIf the input document is invalid or contains more than one YAML document, an error is thrown.\n\n```swift\ndo {\n  let value = try Yaml.load(\"a\\nb: 2\")\n}\ncatch {\n  print(error)  // expected end, near \"b: 2\"\n}\n\n```\n\n\n\n\n\n### Yaml.loadMultiple\n\n```swift\nYaml.loadMultiple (String) throws -\u003e [Yaml]\n```\n\nTakes a string of one or more YAML documents and returns `[Yaml]`.\n\n```swift\nlet value = try! Yaml.loadMultiple(\"---\\na: 1\\nb: 2\\n---\\na: 3\\nb: 4\")\nprint(value[0][\"a\"])  // Int(1)\nprint(value[1][\"a\"])  // Int(3)\n```\n\nIt will throw an error if an error is encountered in any of the documents.\n\n\n\n\n\n### Yaml#[Int] -\u003e Yaml\n\n```swift\nvalue[Int] -\u003e Yaml\nvalue[Int] = Yaml\n```\n\nIf used on a `Yaml.array` value, it will return the value at the specified index. If the index is invalid or the value is not a `Yaml.array`, `Yaml.null` is returned. You can also set a value at a specific index. Enough elements will be added to the wrapped array to set the specified index. If the value is not a `Yaml.array`, it will change to it after set.\n\n```swift\nvar value = try! Yaml.load(\"- Behrang\\n- Maryam\")\nprint(value[0])  // String(Behrang)\nprint(value[1])  // String(Maryam)\nprint(value[2])  // Null\nvalue[2] = \"Radin\"\nprint(value[2])  // String(Radin)\n```\n\n\n\n\n\n### Yaml#[Yaml] -\u003e Yaml\n\n```swift\nvalue[Yaml] -\u003e Yaml\nvalue[Yaml] = Yaml\n```\n\nIf used on a `Yaml.dictionary` value, it will return the value for the specified key. If a value for the specified key does not exist, or value is not a `Yaml.dictionary`, `Yaml.null` is returned. You can also set a value for a specific key. If the value is not a `Yaml.dictionary`, it will change to it after set.\n\nSince `Yaml` is a literal convertible type, you can pass simple values to this method.\n\n```swift\nvar value = try! Yaml.load(\"first name: Behrang\\nlast name: Noruzi Niya\")\nprint(value[\"first name\"])  // String(Behrang)\nprint(value[\"last name\"])  // String(Noruzi Niya)\nprint(value[\"age\"])  // Null\nvalue[\"first name\"] = \"Radin\"\nvalue[\"age\"] = 1\nprint(value[\"first name\"])  // String(Radin)\nprint(value[\"last name\"])  // String(Noruzi Niya)\nprint(value[\"age\"])  // Int(1)\n```\n\n\n\n\n\n### Yaml#bool\n\n```swift\nvalue.bool -\u003e Bool?\n```\n\nReturns an `Optional\u003cBool\u003e` value. If the value is a `Yaml.bool` value, the wrapped value is returned. Otherwise `nil` is returned.\n\n```swift\nlet value = try! Yaml.load(\"animate: true\\nshow tip: false\\nusage: 25\")\nprint(value[\"animate\"].bool)  // Optional(true)\nprint(value[\"show tip\"].bool)  // Optional(false)\nprint(value[\"usage\"].bool)  // nil\n```\n\n\n\n\n\n### Yaml#int\n\n```swift\nvalue.int -\u003e Int?\n```\n\nReturns an `Optional\u003cInt\u003e` value. If the value is a `Yaml.int` value, the wrapped value is returned. Otherwise `nil` is returned.\n\n```swift\nlet value = try! Yaml.load(\"a: 1\\nb: 2.0\\nc: 2.5\")\nprint(value[\"a\"].int)  // Optional(1)\nprint(value[\"b\"].int)  // Optional(2)\nprint(value[\"c\"].int)  // nil\n```\n\n\n\n\n\n### Yaml#double\n\n```swift\nvalue.double -\u003e Double?\n```\n\nReturns an `Optional\u003cDouble\u003e` value. If the value is a `Yaml.double` value, the wrapped value is returned. Otherwise `nil` is returned.\n\n```swift\nlet value = try! Yaml.load(\"a: 1\\nb: 2.0\\nc: 2.5\\nd: true\")\nprint(value[\"a\"].double)  // Optional(1.0)\nprint(value[\"b\"].double)  // Optional(2.0)\nprint(value[\"c\"].double)  // Optional(2.5)\nprint(value[\"d\"].double)  // nil\n```\n\n\n\n\n\n### Yaml#string\n\n```swift\nvalue.string -\u003e String?\n```\n\nReturns an `Optional\u003cString\u003e` value. If the value is a `Yaml.string` value, the wrapped value is returned. Otherwise `nil` is returned.\n\n```swift\nlet value = try! Yaml.load(\"first name: Behrang\\nlast name: Noruzi Niya\\nage: 33\")\nprint(value[\"first name\"].string)  // Optional(\"Behrang\")\nprint(value[\"last name\"].string)  // Optional(\"Noruzi Niya\")\nprint(value[\"age\"].string)  // nil\n```\n\n\n\n\n\n### Yaml#array\n\n```swift\nvalue.array -\u003e [Yaml]?\n```\n\nReturns an `Optional\u003cArray\u003cYaml\u003e\u003e` value. If the value is a `Yaml.array` value, the wrapped value is returned. Otherwise `nil` is returned.\n\n```swift\nlet value = try! Yaml.load(\"languages:\\n - Swift: true\\n - Objective C: false\")\nprint(value.array)  // nil\nprint(value[\"languages\"].array)  // Optional([Dictionary([String(Swift): Bool(true)]), Dictionary([String(Objective C): Bool(false)])])\n```\n\n\n\n\n\n### Yaml#dictionary\n\n```swift\nvalue.dictionary -\u003e [Yaml: Yaml]?\n```\n\nReturns an `Optional\u003cDictionary\u003cYaml, Yaml\u003e\u003e` value. If the value is a `Yaml.dictionary` value, the wrapped value is returned. Otherwise `nil` is returned.\n\n```swift\nlet value = try! Yaml.load(\"- Swift: true\\n- Objective C: false\")\nprint(value.dictionary)  // nil\nprint(value[0].dictionary)  // Optional([String(Swift): Bool(true)])\n```\n\n\n\n\n\n### Yaml#count\n\n```swift\nvalue.count -\u003e Int?\n```\n\nReturns an `Optional\u003cInt\u003e` value. If the value is either a `Yaml.array` or a `Yaml.dictionary` value, the count of elements is returned. Otherwise `nil` is returned.\n\n```swift\nlet value = try! Yaml.load(\"- Swift: true\\n- Objective C: false\")\nprint(value.count)  // Optional(2)\nprint(value[0].count)  // Optional(1)\nprint(value[0][\"Swift\"].count)  // nil\n```\n\n\n\n\n\n## License\n\nMIT\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbehrang%2FYamlSwift","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbehrang%2FYamlSwift","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbehrang%2FYamlSwift/lists"}