{"id":1714,"url":"https://github.com/delba/JASON","last_synced_at":"2025-08-06T13:32:07.026Z","repository":{"id":34272294,"uuid":"38159088","full_name":"delba/JASON","owner":"delba","description":"Fast JSON parsing for Swift","archived":false,"fork":false,"pushed_at":"2021-02-14T06:38:14.000Z","size":904,"stargazers_count":1013,"open_issues_count":5,"forks_count":68,"subscribers_count":23,"default_branch":"master","last_synced_at":"2024-12-01T07:17:47.670Z","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/delba.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}},"created_at":"2015-06-27T12:19:50.000Z","updated_at":"2024-10-28T11:01:57.000Z","dependencies_parsed_at":"2022-09-09T19:01:27.925Z","dependency_job_id":null,"html_url":"https://github.com/delba/JASON","commit_stats":null,"previous_names":[],"tags_count":14,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/delba%2FJASON","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/delba%2FJASON/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/delba%2FJASON/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/delba%2FJASON/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/delba","download_url":"https://codeload.github.com/delba/JASON/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":228708698,"owners_count":17960495,"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-01-05T20:15:54.066Z","updated_at":"2024-12-09T14:30:46.487Z","avatar_url":"https://github.com/delba.png","language":"Swift","funding_links":[],"categories":["Parsing","Libs","JSON/XML Manipulation","Data and Storage","Data Management [🔝](#readme)"],"sub_categories":["JSON","Data Management","Other free courses"],"readme":"\u003cp align=\"center\"\u003e\n  \u003cimg src=\"https://raw.githubusercontent.com/delba/JASON/assets/JASON.png\"\u003e\n\u003c/p\u003e\n\n\u003cp align=\"center\"\u003e\n    \u003ca href=\"https://travis-ci.org/delba/JASON\"\u003e\u003cimg alt=\"Travis Status\" src=\"https://img.shields.io/travis/delba/JASON.svg\"/\u003e\u003c/a\u003e\n    \u003ca href=\"https://img.shields.io/cocoapods/v/JASON.svg\"\u003e\u003cimg alt=\"CocoaPods compatible\" src=\"https://img.shields.io/cocoapods/v/JASON.svg\"/\u003e\u003c/a\u003e\n    \u003ca href=\"https://github.com/Carthage/Carthage\"\u003e\u003cimg alt=\"Carthage compatible\" src=\"https://img.shields.io/badge/Carthage-compatible-4BC51D.svg?style=flat\"/\u003e\u003c/a\u003e\n    \u003ca href=\"https://img.shields.io/cocoapods/p/JASON.svg\"\u003e\u003cimg alt=\"Platform\" src=\"https://img.shields.io/cocoapods/p/JASON.svg\"/\u003e\u003c/a\u003e\n\u003c/p\u003e\n\n**JASON** is a [faster](https://github.com/delba/JASON/tree/benchmarks) `JSON` deserializer written in Swift.\n\n```md\nJASON is the best framework we found to manage JSON at Swapcard. This is by far the fastest and\nthe most convenient out there, it made our code clearer and improved the global performance\nof the app when dealing with large amount of data.\n```\n\u003e *[Gautier Gédoux](https://github.com/gautier-gdx), lead iOS developer at [Swapcard](https://www.swapcard.com/)*\n\n\u003cp align=\"center\"\u003e\n\u003ca href=\"#features\"\u003eFeatures\u003c/a\u003e • \u003ca href=\"#usage\"\u003eUsage\u003c/a\u003e • \u003ca href=\"#example\"\u003eExample\u003c/a\u003e • \u003ca href=\"#references\"\u003eReferences\u003c/a\u003e • \u003ca href=\"#installation\"\u003eInstallation\u003c/a\u003e • \u003ca href=\"#license\"\u003eLicense\u003c/a\u003e\n\u003c/p\u003e\n\n## Features\n\n- [x] Very fast - [`benchmarks`](https://github.com/delba/JASON/tree/benchmarks)\n- [x] Fully tested\n- [x] Fully documented\n\n\u003cp\u003e\u003c/p\u003e\n\n- [x] Clean code\n- [x] Beautiful API\n- [x] Regular updates\n\n\u003cp\u003e\u003c/p\u003e\n\n- [x] Support for iOS, OSX, tvOS, watchOS\n- [x] Compatible with [Carthage](https://github.com/delba/JASON#carthage) / [CocoaPods](https://github.com/delba/JASON#cocoapods)\n- [x] Provide extensions - [`Extensions/`](https://github.com/delba/JASON/tree/master/Extensions)\n\n## Usage\n\n#### Initialization\n\n```swift\nlet json = JSON(anything) // where `anything` is `AnyObject?`\n```\n\nIf you're using [`Alamofire`](https://github.com/Alamofire/Alamofire), include [`JASON+Alamofire.swift`](https://github.com/delba/JASON/blob/master/Extensions/JASON%2BAlamofire.swift) in your project for even more awesomeness:\n\n```swift\nAlamofire.request(.GET, peopleURL).responseJASON { response in\n    if let json = response.result.value {\n        let people = json.map(Person.init)\n        print(\"people: \\(people)\")\n    }\n}\n```\n\nIf you're using [`Moya`](https://github.com/Moya/Moya), check out [`Moya-JASON`](https://github.com/DroidsOnRoids/Moya-JASON)!\n\n#### Parsing\n\nUse subscripts to parse the `JSON` object:\n\n```swift\njson[\"people\"][0][\"name\"]\n\n// Or with a path:\n\njson[path: \"people\", 0, \"name\"]\n```\n\n#### Type casting\n\nCast `JSON` value to its appropriate type by using the computed property `json.\u003ctype\u003e`:\n\n```swift\nlet name = json[\"name\"].string // the name as String?\n```\n\nThe non-optional variant `json.\u003ctype\u003eValue` will return a default value if not present/convertible:\n\n```swift\nlet name = json[\"wrong\"].stringValue // the name will be \"\"\n```\n\nYou can also access the internal value as `AnyObject?` if you want to cast it yourself:\n\n```swift\nlet something = json[\"something\"].object\n```\n\n*See the [References section](https://github.com/delba/JASON#references) for the full list of properties.*\n\n#### `JSONKey`:\n\n\u003e This idea is stolen from [`SwiftyUserDefaults`](https://github.com/radex/SwiftyUserDefaults) by **Radek Pietruszewski** ([GitHub](https://github.com/radex), [Twitter](https://twitter.com/radexp), [Blog](http://radex.io)).\n\u003cbr/\u003e\n\u003e I can't recommend enough to read his article about it! :boom: [Statically-typed NSUserDefaults](http://radex.io/swift/nsuserdefaults/static/) :boom:\n\nDefine and use your `JSONKey` as follow:\n\n```swift\n// With a int key:\n\nlet personKey = JSONKey\u003cJSON\u003e(0)\nlet personJSON = peopleJSON[personKey]\n\n// With a string key:\n\nlet nameKey = JSONKey\u003cString\u003e(\"name\")\nlet name = personJSON[nameKey]\n\n// With a path:\n\nlet twitterURLKey = JSONKey\u003cNSURL?\u003e(path: 0, \"twitter\")\nlet twitterURL = peopleJSON[twitterURLKey]\n```\n\nYou might find more convenient to extend `JSONKeys` as shown in the [Example section](https://github.com/delba/JASON#example).\n\n*See the [References section](https://github.com/delba/JASON#references) for the full list of `JSONKey` types.*\n\n#### Third-party libraries:\n\n- [DroidsOnRoids/**Moya-JASON**](https://github.com/DroidsOnRoids/Moya-JASON) JASON bindings for Moya.\n\n## Example\n\n\u003e This example uses the **Dribbble API** ([docs](http://developer.dribbble.com/v1/)).\n\u003cbr/\u003e\n\u003e An example of the server response can be found in [`Tests/Supporting Files/shots.json`](https://github.com/delba/JASON/blob/master/Tests/Supporting%20Files/shots.json)\n\n- **Step 1:** Extend `JSONKeys` to define your `JSONKey`\n\n```swift\nJSON.dateFormatter.dateFormat = \"yyyy-MM-dd'T'HH:mm:ssZ\"\n\nextension JSONKeys {\n    static let id    = JSONKey\u003cInt\u003e(\"id\")\n    static let createdAt = JSONKey\u003cNSDate?\u003e(\"created_at\")\n    static let updatedAt = JSONKey\u003cNSDate?\u003e(\"updated_at\")\n\n    static let title = JSONKey\u003cString\u003e(\"title\")\n\n    static let normalImageURL = JSONKey\u003cNSURL?\u003e(path: \"images\", \"normal\")\n    static let hidpiImageURL  = JSONKey\u003cNSURL?\u003e(path: \"images\", \"hidpi\")\n\n    static let user = JSONKey\u003cJSON\u003e(\"user\")\n    static let name = JSONKey\u003cString\u003e(\"name\")\n}\n```\n\n- **Step 2:** Create the `Shot` and `User` models\n\n```swift\nstruct Shot {\n    let id: Int\n    let title: String\n\n    let normalImageURL: NSURL\n    var hidpiImageURL: NSURL?\n\n    let createdAt: NSDate\n    let updatedAt: NSDate\n\n    let user: User\n\n    init(_ json: JSON) {\n        id    = json[.id]\n        title = json[.title]\n\n        normalImageURL = json[.normalImageURL]!\n        hidpiImageURL  = json[.hidpiImageURL]\n\n        createdAt = json[.createdAt]!\n        updatedAt = json[.updatedAt]!\n\n        user = User(json[.user])\n    }\n}\n```\n\n```swift\nstruct User {\n    let id: Int\n    let name: String\n\n    let createdAt: NSDate\n    let updatedAt: NSDate\n\n    init(_ json: JSON) {\n        id   = json[.id]\n        name = json[.name]\n\n        createdAt = json[.createdAt]!\n        updatedAt = json[.updatedAt]!\n    }\n}\n```\n\n- **Step 3:** Use the [`JASON+Alamofire.swift`](https://github.com/delba/JASON/blob/master/Extensions/JASON%2BAlamofire.swift) extension to fetch the shots\n\n```swift\nAlamofire.request(.GET, shotsURL).responseJASON { response in\n    if let json = response.result.value {\n        let shots = json.map(Shot.init)\n    }\n}\n```\n\n## References\n\n\u003e Include [`JASON+Properties.swift`](https://github.com/delba/JASON/blob/master/Extensions/JASON%2BProperties.swift) for even more types!\n\nProperty              | JSONKey Type           | Default value\n--------------------- | ---------------------- | -------------\n`string`              | `String?`              |\n`stringValue`         | `String`               | `\"\"`\n`int`                 | `Int?`                 |\n`intValue`            | `Int`                  | `0`\n`double`              | `Double?`              |\n`doubleValue`         | `Double`               | `0.0`\n`float`               | `Float?`               |\n`floatValue`          | `Float`                | `0.0`\n`nsNumber`            | `NSNumber?`            |\n`nsNumberValue`       | `NSNumber`             | `0`\n`cgFloat`             | `CGFloat?`             |\n`cgFloatValue`        | `CGFloat`              | `0.0`\n`bool`                | `Bool?`                |\n`boolValue`           | `Bool`                 | `false`\n`nsDate`              | `NSDate?`              |\n`nsURL`               | `NSURL?`               |\n`dictionary`          | `[String: AnyObject]?` |\n`dictionaryValue`     | `[String: AnyObject]`  | `[:]`\n`jsonDictionary`      | `[String: JSON]?`      |\n`jsonDictionaryValue` | `[String: JSON]`       | `[:]`\n`nsDictionary`        | `NSDictionary?`        |\n`nsDictionaryValue`   | `NSDictionary`         | `NSDictionary()`\n`array`               | `[AnyObject]?`         |\n`arrayValue`          | `[AnyObject]`          | `[]`\n`jsonArray`           | `[JSON]?`              |\n`jsonArrayValue`      | `[JSON]`               | `[]`\n`nsArray`             | `NSArray?`             |\n`nsArrayValue`        | `NSArray`              | `NSArray()`\n\n\u003e Configure JSON.dateFormatter if needed for `nsDate` parsing\n\n## Installation\n\n#### Carthage\n\n[Carthage](https://github.com/Carthage/Carthage) is a decentralized dependency manager that automates the process of adding frameworks to your Cocoa application.\n\nYou can install Carthage with [Homebrew](http://brew.sh/) using the following command:\n\n```bash\n$ brew update\n$ brew install carthage\n```\n\nTo integrate **`JASON`** into your Xcode project using Carthage, specify it in your `Cartfile`:\n\n```ogdl\ngithub \"delba/JASON\" \u003e= 3.0\n```\n\n#### CocoaPods\n\n[CocoaPods](http://cocoapods.org) is a dependency manager for Cocoa projects.\n\nYou can install it with the following command:\n\n```bash\n$ gem install cocoapods\n```\n\nTo integrate **`JASON`** into your Xcode project using CocoaPods, specify it in your `Podfile`:\n\n```ruby\nuse_frameworks!\n\npod 'JASON', '~\u003e 3.0'\n```\n\n## License\n\nCopyright (c) 2015-2019 Damien (http://delba.io)\n\nPermission is hereby granted, free of charge, to any person obtaining a copy\nof this software and associated documentation files (the \"Software\"), to deal\nin the Software without restriction, including without limitation the rights\nto use, copy, modify, merge, publish, distribute, sublicense, and/or sell\ncopies of the Software, and to permit persons to whom the Software is\nfurnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all\ncopies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\nFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\nAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\nLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\nOUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\nSOFTWARE.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdelba%2FJASON","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdelba%2FJASON","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdelba%2FJASON/lists"}