{"id":15038755,"url":"https://github.com/mukeshydv/jsonparserswift","last_synced_at":"2026-01-10T03:57:43.694Z","repository":{"id":56916517,"uuid":"81299322","full_name":"mukeshydv/JSONParserSwift","owner":"mukeshydv","description":"Framework for easily parsing your JSON data directly to Swift object.","archived":true,"fork":false,"pushed_at":"2018-05-03T10:59:21.000Z","size":291,"stargazers_count":11,"open_issues_count":1,"forks_count":6,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-09-20T16:31:19.928Z","etag":null,"topics":["ios","ios-swift","json","json-parser","json-parsing","json-parsing-swift","parse","parser","respective-datatypes","swift","swift-3","swift-framework","swift4"],"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/mukeshydv.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":"2017-02-08T07:12:04.000Z","updated_at":"2023-01-28T18:58:58.000Z","dependencies_parsed_at":"2022-08-21T03:50:45.470Z","dependency_job_id":null,"html_url":"https://github.com/mukeshydv/JSONParserSwift","commit_stats":null,"previous_names":[],"tags_count":13,"template":false,"template_full_name":null,"purl":"pkg:github/mukeshydv/JSONParserSwift","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mukeshydv%2FJSONParserSwift","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mukeshydv%2FJSONParserSwift/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mukeshydv%2FJSONParserSwift/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mukeshydv%2FJSONParserSwift/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mukeshydv","download_url":"https://codeload.github.com/mukeshydv/JSONParserSwift/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mukeshydv%2FJSONParserSwift/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":278259829,"owners_count":25957547,"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-04T02:00:05.491Z","response_time":63,"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":["ios","ios-swift","json","json-parser","json-parsing","json-parsing-swift","parse","parser","respective-datatypes","swift","swift-3","swift-framework","swift4"],"created_at":"2024-09-24T20:40:03.224Z","updated_at":"2025-10-04T03:32:00.435Z","avatar_url":"https://github.com/mukeshydv.png","language":"Swift","funding_links":[],"categories":[],"sub_categories":[],"readme":"![Json_Parser_Image](json_parser.png)\n\n[![CI Status](http://img.shields.io/travis/mukeshydv/JSONParserSwift.svg?style=flat)](https://travis-ci.org/mukeshydv/JSONParserSwift)\n[![Version](https://img.shields.io/cocoapods/v/JSONParserSwift.svg?style=flat)](http://cocoadocs.org/docsets/JSONParserSwift)\n[![License](https://img.shields.io/badge/license-MIT-blue.svg?style=flat)](http://mit-license.org)\n[![Platform](https://img.shields.io/cocoapods/p/JSONParserSwift.svg?style=flat)](http://cocoadocs.org/docsets/JSONParserSwift)\n[![Language](https://img.shields.io/badge/swift-4.0-orange.svg)](https://developer.apple.com/swift)\n[![codecov.io](https://codecov.io/gh/mukeshydv/JSONParserSwift/branch/master/graphs/badge.svg)](https://codecov.io/gh/mukeshydv/JSONParserSwift/branch/master)\n\nServer sends the all JSON data in black and white format i.e. its all strings \u0026 we make hard efforts to typecast them into their respective datatypes as per our model class.\n\nNow, there's comes `JSONParserSwift` framework between the server data and our code to magically converts those strings into the required respective datatypes as per our model classes without writing any code.\n\n## Requirements\n\n## Installation\n\nJSONParserSwift is available through [CocoaPods](http://cocoapods.org). To install\nit, simply add the following line to your Podfile:\n\n```ruby\npod \"JSONParserSwift\"\n```\n### Swift 3 support\nFor using the framework on Swift 3 use the branch [swift-3.2](https://github.com/mukeshydv/JSONParserSwift/tree/swift-3.2) or install version `1.1.3` using CocoaPods, use following line in your Podfile:\n\n```ruby\npod 'JSONParserSwift', '1.1.3'\n```\n\n## Implementation\n\nTo parse any JSON String or Dictionary to your model you have to create a class and subclass it by `ParsableModel`. Now you will need to create the properties in the model class. You can create these properties with same name or different name as keys in json string. If you declare properties with same name as key in json then you need to declare only properties. But if you want to have different names for properties and keys then you need to conform protocol `JSONKeyCoder` and implement method \n`func key(for key: String) -\u003e String?`\n\n### Example\n\nIf you have to parse following JSON String:\n```json\n{\n  \"responseStatus\": {\n    \"statusCode\": 101,\n    \"message\": \"Error Message\"\n  },\n  \"responseData\": {\n    \"employeeId\": 1002,\n    \"employeeName\": \"Demo Employee\",\n    \"employeeEmail\": \"abc@def.com\",\n    \"employeeDepartment\": \"IT\"\n  }\n}\n```\nYou will need to create models as follows:\n\n```swift\nclass BaseResponse: ParsableModel {\n  var responseStatus: ResponseStatus?\n  var responseData: Employee?\n}\n\nclass ResponseStatus: ParsableModel {\n  var statusCode: NSNumber?\n  var message: String?\n}\n\nclass Employee: ParsableModel {\n  var employeeId: NSNumber?\n  var employeeName: String?\n  var employeeEmail: String?\n  var employeeDepartment: String?\n}\n```\n\nNow to parse the JSON you just need to call following method:\n\n```swift\ndo {\n  let baseResponse: BaseResponse = try JSONParserSwift.parse(string: jsonString)\n  // Use base response object here\n} catch {\n  print(error)\n}\n```\nThe model can have reference to other model's which are subclass of `ParsableModel` or it can have `Array` of models.\n\n### Get JSON String from Object\n\nTo get the JSON string from an object you just have to call `JSONParserSwift.getJSON(object: NSObject)` method to get the JSON.\n\nIf you want to have different keys and properties name then Conform to protocol `JSONKeyCoder` and implement its method `key(for key: String) -\u003e String?` as given below:\n\n```swift\nclass TestModel: JSONKeyCoder {\n\n    var test: String?\n    var number: Double = 0\n    var boolValue: Bool = false\n    var anotherTest: TestModel?\n    var array: [TestModel]?\n    \n    public func key(for key: String) -\u003e String? {\n        switch key {\n        case \"boolValue\":   // Properties name\n            return \"bool_value\"     // Key in response\n        case \"anotherTest\":\n            return \"another_key\"\n        default:\n            return nil\n        }\n    }\n}\n```\n\nIf you want to convert the model object into JSON string then call method getJSON as given below:\n\n```swift\n// Prepare Test Model\nlet testModel: TestModel = TestModel()\ntestModel.test = \"xyz\"\ntestModel.number = 10.0\ntestModel.boolValue = true\n    \nlet anotherTestModel = TestModel()\nanotherTestModel.test = \"abc\"\nanotherTestModel.number = 23\nanotherTestModel.boolValue = false\n    \ntestModel.anotherTest = anotherTestModel\ntestModel.array = [anotherTestModel]\n\ndo {\n    // Convert into json string\n    let jsonString = try JSONParserSwift.getJSON(object: testModel)\n    print(\"Json String : \\(jsonString)\")\n} catch {\n    print(error)\n}\n```\n\nThe JSON string for the above code will be:\n\n```json\n{\n  \"bool_value\":true,\n  \"number\":10,\n  \"test\":\"xyz\",\n  \"array\":[\n    {\n      \"bool_value\":false,\n      \"number\":23,\n      \"test\":\"abc\",\n      \"array\": null,\n      \"another_key\": null\n    }\n  ],\n  \"another_key\": {\n    \"bool_value\":false,\n    \"number\":23,\n    \"test\":\"abc\",\n    \"array\": null,\n    \"another_key\": null\n  }\n }\n```\n\n**Note:** Currently this version do not support Optionals with Int and Array of Optional types. So prefer to use NSNumber for number related datas.\n\n## Author\n\n* [**Mukesh Yadav**](https://github.com/mukeshydv)\n* [**Chanchal Chauhan**](https://github.com/chanchalchauhan)\n\nSee also the list of [contributors](https://github.com/mukeshydv/JSONParserSwift/graphs/contributors) who participated in this project.\n\n## License\n\nJSONParserSwift is available under the MIT license. See the LICENSE file for more info.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmukeshydv%2Fjsonparserswift","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmukeshydv%2Fjsonparserswift","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmukeshydv%2Fjsonparserswift/lists"}