{"id":20492550,"url":"https://github.com/redmadrobot/core-parser","last_synced_at":"2025-07-13T10:35:59.615Z","repository":{"id":56906696,"uuid":"111562363","full_name":"RedMadRobot/core-parser","owner":"RedMadRobot","description":null,"archived":false,"fork":false,"pushed_at":"2018-08-24T15:03:11.000Z","size":55,"stargazers_count":3,"open_issues_count":0,"forks_count":2,"subscribers_count":8,"default_branch":"master","last_synced_at":"2025-04-13T17:03:10.419Z","etag":null,"topics":["json","mapper","networking","parser","serialization"],"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/RedMadRobot.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-11-21T14:51:53.000Z","updated_at":"2018-08-24T11:31:47.000Z","dependencies_parsed_at":"2022-08-21T03:20:47.015Z","dependency_job_id":null,"html_url":"https://github.com/RedMadRobot/core-parser","commit_stats":null,"previous_names":[],"tags_count":6,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/RedMadRobot%2Fcore-parser","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/RedMadRobot%2Fcore-parser/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/RedMadRobot%2Fcore-parser/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/RedMadRobot%2Fcore-parser/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/RedMadRobot","download_url":"https://codeload.github.com/RedMadRobot/core-parser/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248750073,"owners_count":21155685,"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":["json","mapper","networking","parser","serialization"],"created_at":"2024-11-15T17:29:36.050Z","updated_at":"2025-04-13T17:03:19.717Z","avatar_url":"https://github.com/RedMadRobot.png","language":"Swift","readme":"# CoreParser\n\n## Features\n* Recursive parse algorithm\n* Parse primitive types\n* Different log levels\n\n## Installation\nCocoapods\n\n```ruby\npod 'CoreParser'\n```\n\n## Usage\n\nLet's assume you object user. It has mandatory and optional field. In swift it looks like this.\n\n```swift\nclass User {\n\n\tvar firstName: String = \"\"\n\t\n\tvar secondName: String = \"\"\n\t\n\tvar middleName: String? = nil\n\n}\n```\n\nThat means first and last name is mandatory, middle name is optional. So if you get user from server without mandatory field it should be rejected. For instance\n\n```javascript\n{\n\t\"user\": {\n\t\t\"last_name\": \"Appleseed\",\n\t\t\"middle_name\": \"Key\"\n\t}\n}\n```\n\nIt's really important in practice to deny \"wrong\" objects: it can crash your app, if you use only optional types or leads to undefined behaviour.\n\n```swift\n// Convert Data into object (dictionary or array) after network response \nlet json = try JSONSerialization.jsonObject(with: jsonData, options: [])\n\n// Initialize your parser with required log level\nlet parser = AccountParser(logLevel: .logMandatoryFields)\n\n// Parse response\n// If you wait only one object, just add .first in the end\nlet users = parser.parse(json)\n\n```\n\nParser for user looks like this\n\n```swift\nclass UserParser: JSONParser\u003cUser\u003e {\n    \n    override func parseObject(_ data: JSON) -\u003e User? {\n\n\t     // call this method only if you need logs\n        printAbsentFields(in: data)\n        \n        // checking for mandatory fields\n        guard\n            let firstName = data[\"first_name\"]?.string,\n            let lastName = data[\"last_name\"]?.string\n        else {\n            return nil\n        }\n        \n        let object = User()\n        object.firstName = firstName\n        object.lastName = lastName\n        object.middleName = data[\"middle_name\"]?.string\n        \n        return object\n    }\n    \n    \n    // override this method only if you need logs\n    override class func modelFields() -\u003e Fields {\n        return Fields(\n            mandatory: Set([\"first_name\", \"last_name\"]),\n            optional: Set([\"middle_name\"])\n        )\n    }\n    \n}\n\n```\n\nIf your back-end changes key `user` for `data` it continue to work due to its algorithm: JSON keys are analyzed only for properties, that parser try to find recursively.\n\nFor more info please look at the example project.\n\n\n## TODOs\n* Create and return errors for failed parse objects\n* Log error only once for single object\n\n## Authors\nIvan Vavilov, iv@redmadrobot.com\n\nAndrey Rozhkov, ar@redmadrobot.com\n\n\n## Requirements\n* Xcode 9\n* Swift 4\n* iOS 8\n\n## License\nCoreParser is available under the MIT license. See the LICENSE file for more info.","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fredmadrobot%2Fcore-parser","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fredmadrobot%2Fcore-parser","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fredmadrobot%2Fcore-parser/lists"}