{"id":1735,"url":"https://github.com/ikesyo/Himotoki","last_synced_at":"2025-08-06T13:32:17.205Z","repository":{"id":32133816,"uuid":"35706498","full_name":"ikesyo/Himotoki","owner":"ikesyo","description":"A type-safe JSON decoding library purely written in Swift","archived":false,"fork":false,"pushed_at":"2019-09-01T07:54:17.000Z","size":377,"stargazers_count":796,"open_issues_count":3,"forks_count":47,"subscribers_count":25,"default_branch":"master","last_synced_at":"2024-12-08T17:44:53.315Z","etag":null,"topics":["decoding","json","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/ikesyo.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2015-05-16T02:25:18.000Z","updated_at":"2024-10-06T13:21:36.000Z","dependencies_parsed_at":"2022-07-08T11:46:58.102Z","dependency_job_id":null,"html_url":"https://github.com/ikesyo/Himotoki","commit_stats":null,"previous_names":[],"tags_count":37,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ikesyo%2FHimotoki","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ikesyo%2FHimotoki/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ikesyo%2FHimotoki/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ikesyo%2FHimotoki/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ikesyo","download_url":"https://codeload.github.com/ikesyo/Himotoki/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":228770387,"owners_count":17969906,"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":["decoding","json","swift"],"created_at":"2024-01-05T20:15:54.551Z","updated_at":"2024-12-09T14:30:47.751Z","avatar_url":"https://github.com/ikesyo.png","language":"Swift","readme":"# Himotoki\n\n[![Join the chat at https://gitter.im/ikesyo/Himotoki](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/ikesyo/Himotoki?utm_source=badge\u0026utm_medium=badge\u0026utm_campaign=pr-badge\u0026utm_content=badge)\n\n[![GitHub release](https://img.shields.io/github/release/ikesyo/Himotoki.svg)](https://github.com/ikesyo/Himotoki/releases)\n[![CI Status](https://travis-ci.org/ikesyo/Himotoki.svg)](https://travis-ci.org/ikesyo/Himotoki)\n[![Carthage compatible](https://img.shields.io/badge/Carthage-compatible-4BC51D.svg?style=flat)](https://github.com/Carthage/Carthage)\n[![Swift Package Manager](https://img.shields.io/badge/Swift%20Package%20Manager-compatible-brightgreen.svg)](https://github.com/apple/swift-package-manager)\n\nHimotoki (紐解き) is a type-safe JSON decoding library written purely in Swift. This library is highly inspired by the popular Swift JSON parsing libraries: [Argo](https://github.com/thoughtbot/Argo) and [ObjectMapper](https://github.com/Hearst-DD/ObjectMapper).\n\n_Himotoki_ has the same meaning of 'decoding' in Japanese.\n\n- Just do JSON decoding (deserialization) well. JSON encoding (serialization) will not be supported going forward. :wink:\n- Much simpler API.\n- Fail-fast conditional model building. This is useful for some `struct`s with non-optional `let` properties.\n- No external dependencies.\n\nLet's take a look at a simple example:\n\n```swift\nstruct Group: Himotoki.Decodable {\n    let name: String\n    let floor: Int\n    let locationName: String\n    let optional: [String]?\n\n    // MARK: Himotoki.Decodable\n\n    static func decode(_ e: Extractor) throws -\u003e Group {\n        return try Group(\n            name: e \u003c| \"name\",\n            floor: e \u003c| \"floor\",\n            locationName: e \u003c| [ \"location\", \"name\" ], // Parse nested objects\n            optional: e \u003c|? \"optional\" // Parse optional arrays of values\n        )\n    }\n}\n\nfunc testGroup() {\n    var JSON: [String: AnyObject] = [ \"name\": \"Himotoki\", \"floor\": 12 ]\n    \n    let g = try? Group.decodeValue(JSON)\n    XCTAssert(g != nil)\n    XCTAssert(g?.name == \"Himotoki\")\n    XCTAssert(g?.floor == 12)\n    XCTAssert(g?.optional == nil)\n\n    JSON[\"name\"] = nil\n    do {\n        try Group.decodeValue(JSON)\n    } catch let DecodeError.MissingKeyPath(keyPath) {\n        XCTAssert(keyPath == \"name\")\n    } catch {\n        XCTFail()\n    }\n}\n```\n\n:warning: __Please note that you should need to add the module name `Himotoki` to `Decodable` (`Himotoki.Decodable`) to avoid type name collision with `Foundation.Decodable` in Xcode 9 or later.__ :warning:\n\n## Implementing the `decode` method for your models\n\nTo implement the `decode` method for you models conforming to the `Decodable` protocol, you can use the following `Extractor`'s extraction methods:\n\n- `public func value\u003cT: Decodable\u003e(_ keyPath: KeyPath) throws -\u003e T`\n- `public func valueOptional\u003cT: Decodable\u003e(_ keyPath: KeyPath) throws -\u003e T?`\n- `public func array\u003cT: Decodable\u003e(_ keyPath: KeyPath) throws -\u003e [T]`\n- `public func arrayOptional\u003cT: Decodable\u003e(_ keyPath: KeyPath) throws -\u003e [T]?`\n- `public func dictionary\u003cT: Decodable\u003e(_ keyPath: KeyPath) throws -\u003e [String: T]`\n- `public func dictionaryOptional\u003cT: Decodable\u003e(_ keyPath: KeyPath) throws -\u003e [String: T]?`\n\n### Extraction Operators\n\nHimotoki also supports the following operators to decode JSON elements, where `T` is a generic type conforming to the `Decodable` protocol.\n\n| Operator  | Decode element as | Remarks                          |\n|:----------|:------------------|:---------------------------------|\n| `\u003c\\|`     | `T`               | A value                          |\n| `\u003c\\|?`    | `T?`              | An optional value                |\n| `\u003c\\|\\|`   | `[T]`             | An array of values               |\n| `\u003c\\|\\|?`  | `[T]?`            | An optional array of values      |\n| `\u003c\\|-\\|`  | `[String: T]`     | A dictionary of values           |\n| `\u003c\\|-\\|?` | `[String: T]?`    | An optional dictionary of values |\n\n## Value Transformation\n\nYou can transform an extracted value to an instance of non-`Decodable` types by passing the value to a `Transformer` instance as follows:\n\n```swift\n// Creates a `Transformer` instance.\nlet URLTransformer = Transformer\u003cString, URL\u003e { urlString throws -\u003e URL in\n    if let url = URL(string: urlString) {\n        return url\n    }\n    \n    throw customError(\"Invalid URL string: \\(urlString)\")\n}\n\nlet url: URL = try URLTransformer.apply(e \u003c| \"foo_url\")\nlet otherURLs: [URL] = try URLTransformer.apply(e \u003c| \"bar_urls\")\n```\n\n## Requirements\n\nHimotoki 4.x requires / supports the following environments:\n\n- Swift 4.2 / Xcode 10.1 or later\n- OS X 10.9 or later\n- iOS 8.0 or later\n- tvOS 9.0 or later\n- watchOS 2.0 or later\n- [Linux](https://swift.org/download/#linux) is also supported\n\n## Installation\n\nCurrently Himotoki supports installation via the package managers [Carthage](https://github.com/Carthage/Carthage) and [CocoaPods](https://cocoapods.org/).\n\n### Carthage\n\nHimotoki is [Carthage](https://github.com/Carthage/Carthage) compatible.\n\n- Add `github \"ikesyo/Himotoki\" ~\u003e 3.1` to your Cartfile.\n- Run `carthage update`.\n\n### CocoaPods\n\nHimotoki also can be used by [CocoaPods](https://cocoapods.org/).\n\n- Add the followings to your Podfile:\n\n    ```ruby\n    use_frameworks!\n    pod \"Himotoki\", \"~\u003e 3.1\"\n    ```\n\n- Run `pod install`.\n\n## License\n\nHimotoki is released under the [MIT License](LICENSE.md).\n","funding_links":[],"categories":["Parsing","Libs","JSON Parse","Data Management [🔝](#readme)","JSON"],"sub_categories":["JSON","Data Management","Other free courses"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fikesyo%2FHimotoki","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fikesyo%2FHimotoki","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fikesyo%2FHimotoki/lists"}