{"id":32147205,"url":"https://github.com/molbie/outlaw","last_synced_at":"2025-10-21T08:54:26.179Z","repository":{"id":62449731,"uuid":"74856053","full_name":"Molbie/Outlaw","owner":"Molbie","description":"JSON mapper for macOS, iOS, tvOS, and watchOS","archived":false,"fork":false,"pushed_at":"2020-04-01T22:41:46.000Z","size":184,"stargazers_count":24,"open_issues_count":0,"forks_count":3,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-10-21T08:53:55.127Z","etag":null,"topics":["extraction","ios","json","macos","mapper","marshal","swift","tvos","watchos"],"latest_commit_sha":null,"homepage":null,"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/Molbie.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":"2016-11-26T23:23:55.000Z","updated_at":"2021-07-29T21:32:45.000Z","dependencies_parsed_at":"2022-11-01T23:17:08.325Z","dependency_job_id":null,"html_url":"https://github.com/Molbie/Outlaw","commit_stats":null,"previous_names":[],"tags_count":14,"template":false,"template_full_name":null,"purl":"pkg:github/Molbie/Outlaw","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Molbie%2FOutlaw","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Molbie%2FOutlaw/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Molbie%2FOutlaw/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Molbie%2FOutlaw/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Molbie","download_url":"https://codeload.github.com/Molbie/Outlaw/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Molbie%2FOutlaw/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":280232858,"owners_count":26295149,"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","status":"online","status_checked_at":"2025-10-21T02:00:06.614Z","response_time":58,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"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":["extraction","ios","json","macos","mapper","marshal","swift","tvos","watchos"],"created_at":"2025-10-21T08:54:25.180Z","updated_at":"2025-10-21T08:54:26.174Z","avatar_url":"https://github.com/Molbie.png","language":"Swift","readme":"![License](https://img.shields.io/dub/l/vibe-d.svg)\n![Platforms](https://img.shields.io/badge/Platforms-macOS%20%7C%20iOS%20%7C%20tvOS%20%7C%20watchOS-lightgrey.svg)\n[![Build Status](https://travis-ci.org/Molbie/Outlaw.svg?branch=master)](https://travis-ci.org/Molbie/Outlaw)\n[![codecov](https://codecov.io/gh/Molbie/Outlaw/branch/master/graph/badge.svg)](https://codecov.io/gh/Molbie/Outlaw)\n\n\n# Outlaw\n\nIn Swift, we all deal with JSON, plists, and various forms of `[String: Any]`. `Outlaw` provides various ways to deal with these in an expressive and type safe way. `Outlaw` will help you write declarative, performant, error handled code using the power of __Protocol Oriented Programming™__.\n\n\n## Usage\n\nExtracting values from `[String: Any]` using Outlaw is as easy as\n\n```swift\nlet name: String = try json.value(for: \"name\")\nlet url: URL = try json.value(for: \"user.website\") // extract from nested objects!\n```\n\n\n## Converting to Models\n\nOften we want to take an extractable object (like `[String: Any]`) and deserialize it into one of our local models—for example we may want to take some JSON and initialize one of our local models with it:\n\n```swift\nstruct User: Deserializable {\n    var id: Int\n    var name: String\n    var email: String\n\n    init(object: Extractable) throws {\n        id = try object.value(for: \"id\")\n        name = try object.value(for: \"name\")\n        email = try object.value(for: \"email\")\n    }\n}\n```\n\nNow, just by virtue of supplying a simple initializer you can *pull your models directly out of `[String: Any]`*!\n\n```swift\nlet users: [User] = try json.value(for: \"users\")\n```\n\nThat was easy! Thanks, Protocol Oriented Programming™!\n\n\n## Serializing Models\n\nWe've looked at going from our `[String: Any]` into our local models, but what about the other way around?\n\n```swift\nextension User: Serializable {\n\tfunc serialized() -\u003e [String: Any] {\n        return [\n            \"id\": \"id\",\n            \"name\" : name,\n            \"email\": email\n        ]\n    }\n}\n```\n\nNow, you might be thinking \"but couldn't I use reflection to do this for me automagically?\" You could. And if you're into that, there are some other great frameworks for you to use. But Outlaw believes mirrors can lead down the road to a world of hurt. Outlaw lives in a world where What You See Is What You Get™, and you can easily adapt to APIs that snake case, camel case, or whatever case your backend developers are into. Outlaw code is explicit and declarative. But don't just take Outlaw's word for it—read the good word towards the end [here on the official Swift blog.](https://developer.apple.com/swift/blog/?id=37)\n\n\n## Error Handling\n\nAre you someone that doesn't care about errors? Use an optional data type. \n\n```swift\nlet users: [User]? = json.value(for: \"users\")\n```\n\nOtherwise, wrap your code in a `do-catch` to get all the juicy details when things go wrong.\n\n```swift\ndo {\n\tlet users: [User] = try json.value(for: \"users\")\n}\ncatch {\n\tprint(error)\n}\n```\n\n\n## Add Your Own Values\n\nOut of the box, `Outlaw` supports extracting native Swift types like `String`, `Int`, etc., as well as `URL`, `Date` and anything conforming to `Deserializable`, and arrays or dictionaries of all the aforementioned types. \n\nHowever, Outlaw doesn't just leave you up the creek without a paddle! Adding your own Outlaw value type is as easy as extending your type with `Value`.\n\n```swift\nextension CGPoint: Value {\n    public static func value(from object: Any) throws -\u003e CGPoint {\n        guard let properties = object as? [String: CGFloat] else {\n            throw OutlawError.typeMismatch(expected: [String: CGFloat].self, actual: type(of: object))\n        }\n        let x: CGFloat = properties[\"x\"] ?? 0\n        let y: CGFloat = properties[\"y\"] ?? 0\n        \n        return CGPoint(x: x, y: y)\n    }\n}\n```\n\nBy simply implementing `value(from:)`, Outlaw allows you to immediately do this:\n\n```swift\nlet point: CGPoint = try json.value(for: \"point\")\n```\n\nProtocol Oriented Programming™ strikes again!\n\n\n## Intermediate Values\n\nDon't like how `Outlaw` implements the default value extraction? Have a different date format? No problem! All you need is a transformation function when extracting the values.\n\n```swift\nlet formatter = DateFormatter()\nformatter.timeZone = TimeZone(abbreviation: \"GMT\")\nformatter.dateFormat = \"MM/dd/yyyy\"\n\nlet date: Date? = json.value(for: \"date\", with: { (dateString: String) -\u003e Date? in\n\treturn formatter.date(from: dateString)\n})\n```\n\nWe can also use the power of swift and shorten the above code to:\n\n```swift\nlet date: Date? = json.value(for: \"date\", with: formatter.date)\n```\n\n\n# Performance\n\nOutlaw is based on the same underlying code as [Marshal](https://github.com/utahiosmac/Marshal) and is just as performant. You should always take benchmarks with a grain of salt, but chew on [these benchmarks](https://github.com/bwhiteley/JSONShootout) for a bit anyway. Unfortunately, the JSONShootout project was built in a way so that Outlaw can't be added because of ambiguous method collisions with Marshal.\n\n\n# Goal\n\n`Outlaw` was created by one of the main contributors to [Marshal](https://github.com/utahiosmac/Marshal). However, `Marshal` was designed to be a bare bones framework that needed to be extended for additional features. `Outlaw` was designed to be a more feature rich framework that can handle a lot more data extraction scenarios out of the box.\n\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmolbie%2Foutlaw","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmolbie%2Foutlaw","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmolbie%2Foutlaw/lists"}