{"id":21198379,"url":"https://github.com/netyouli/sexyjson","last_synced_at":"2025-10-19T15:08:42.726Z","repository":{"id":62455250,"uuid":"92491262","full_name":"netyouli/SexyJson","owner":"netyouli","description":"SexyJson is Swift5.+ json parse open source library quickly and easily, perfect supporting class and struct model, fully oriented protocol architecture, support iOS and MAC OS X","archived":false,"fork":false,"pushed_at":"2020-01-14T09:22:29.000Z","size":582,"stargazers_count":67,"open_issues_count":1,"forks_count":14,"subscribers_count":8,"default_branch":"master","last_synced_at":"2024-11-17T13:49:56.960Z","etag":null,"topics":["json-parser","kvc-model","objectmapper","sexyjson","swiftyjson"],"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/netyouli.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-05-26T08:48:14.000Z","updated_at":"2023-05-10T14:27:27.000Z","dependencies_parsed_at":"2022-11-02T00:16:55.811Z","dependency_job_id":null,"html_url":"https://github.com/netyouli/SexyJson","commit_stats":null,"previous_names":[],"tags_count":15,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/netyouli%2FSexyJson","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/netyouli%2FSexyJson/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/netyouli%2FSexyJson/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/netyouli%2FSexyJson/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/netyouli","download_url":"https://codeload.github.com/netyouli/SexyJson/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":225622929,"owners_count":17498168,"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-parser","kvc-model","objectmapper","sexyjson","swiftyjson"],"created_at":"2024-11-20T19:50:58.634Z","updated_at":"2025-10-19T15:08:37.691Z","avatar_url":"https://github.com/netyouli.png","language":"Swift","funding_links":[],"categories":[],"sub_categories":[],"readme":"# SexyJson\n\n![Build Status](https://api.travis-ci.org/netyouli/SexyJson.svg?branch=master)\n[![Pod Version](http://img.shields.io/cocoapods/v/SexyJson.svg?style=flat)](http://cocoadocs.org/docsets/SexyJson/)\n[![Platform](https://img.shields.io/cocoapods/p/SnapKit.svg?style=flat)](https://github.com/netyouli/)\n[![Pod License](http://img.shields.io/cocoapods/l/SexyJson.svg?style=flat)](https://opensource.org/licenses/MIT)\n\nSexyJson is Swift5+ json parse open source library quickly and easily, perfect supporting class and struct model, support the KVC model, fully oriented protocol architecture, support iOS and MAC OS X\n\n**Objective-c version** 👉 [WHC_Model](https://github.com/netyouli/WHC_Model)\n\nupdate：Support for compatible swift5.+\n\nNote\n==============\n- The definition of model must implement SexyJson protocol\n- If you have any enumeration type must be specified in the definition of model data type and implementation SexyJsonEnumType protocol\n- If you want to use **swift3.2**, please pod SexyJson '~\u003e 0.0.4'\n\nRequire\n==============\n* iOS 8.0+ / Mac OS X 10.11+ / tvOS 9.0+\n* Xcode 8.0 or later\n* Swift 5.0\n\nInstall\n==============\n* CocoaPods: pod 'SexyJson'\n\nModel\n==============\nThis is an example of json:\n```swift\nlet json = \"{\\\"age\\\":25,\\\"enmuStr\\\":\\\"Work\\\",\\\"url\\\":\\\"https:\\\\/\\\\/www.baidu.com\\\",\n            \\\"subArray\\\":[{\\\"test3\\\":\\\"test3\\\",\\\"test2\\\":\\\"test2\\\",\\\"cls\\\":{\\\"age\\\":10,\n            \\\"name\\\":\\\"swift\\\"},\\\"test1\\\":\\\"test1\\\"},{\\\"test3\\\":\\\"test3\\\",\\\"test2\\\":\\\"test2\\\",\n            \\\"cls\\\":{\\\"age\\\":10,\\\"name\\\":\\\"swift\\\"},\\\"test1\\\":\\\"test1\\\"}],\\\"color\\\":\\\"0xffbbaa\\\",\n            \\\"nestArray\\\":[[{\\\"test\\\":\\\"test1\\\"},{\\\"test\\\":\\\"test2\\\"}],[{\\\"test\\\":\\\"test3\\\"},\n            {\\\"test\\\":\\\"test4\\\"}]],\\\"enmuInt\\\":10,\\\"sub\\\":{\\\"test1\\\":\\\"test1\\\",\\\"test2\\\":\\\"test2\\\",\n            \\\"test3\\\":\\\"test3\\\"},\\\"height\\\":175,\\\"intArray\\\":[1,2,3,4],\\\"name\\\":\\\"吴海超\\\",\n            \\\"learn\\\":[\\\"iOS\\\",\\\"android\\\",\\\"js\\\",\\\"nodejs\\\",\\\"python\\\"]}\"\n```\nThe model class:\n```swift\nenum WorkEnum: String,SexyJsonEnumType {\n    case null = \"nil\"\n    case one = \"Work\"\n    case two = \"Not Work\"\n}\n\nenum IntEnum: Int,SexyJsonEnumType {\n    case zero = 0\n    case hao = 10\n    case xxx = 20\n}\n\nstruct Model :SexyJson {\n\n    var age: Int = 0\n    var enmuStr: WorkEnum!\n    var url: URL!\n    var subArray: [SubArray]!\n    var color: UIColor!\n    var nestArray: [[NestArray]]?\n    var enmuInt: IntEnum = .xxx\n    var sub: Sub!\n    var height: Int = 0\n    var intArray: [Int]!\n    var name: String!\n    var learn: [String]!\n\n    /// Model mapping\n    public mutating func sexyMap(_ map: [String : Any]) {\n        age      \u003c\u003c\u003c   map[\"age\"]\n        enmuStr  \u003c\u003c\u003c   map[\"enmuStr\"]\n        url      \u003c\u003c\u003c   map[\"url\"]\n        subArray \u003c\u003c\u003c   map[\"subArray\"]\n        color    \u003c\u003c\u003c   map[\"color\"]\n        nestArray \u003c\u003c\u003c  map[\"nestArray\"]\n        enmuInt   \u003c\u003c\u003c  map[\"enmuInt\"]\n        sub       \u003c\u003c\u003c  map[\"sub\"]\n        height    \u003c\u003c\u003c  map[\"height\"]\n        intArray  \u003c\u003c\u003c  map[\"intArray\"]\n        name      \u003c\u003c\u003c  map[\"name\"]\n        learn     \u003c\u003c\u003c  map[\"learn\"]\n    }\n}\n\n```\n**You don't need to manually create the SexyJson model class you can use open source tools with the help of** [WHC_DataModel.app](https://github.com/netyouli/WHC_DataModelFactory) **automatically created SexyJson model**\n\nUsage\n==============\n\nJson is converted into a model object(json -\u003e model)\n```swift\nlet model = Model.sexy_json(json)\n```\n\nModel object converted into the dictionary(model -\u003e dictionary)\n```swift\nlet dictionary = model.sexy_dictionary()\n```\n\nModel object converted into the json string(model -\u003e json)\n```swift\nlet jsonStr = model.sexy_json()\n```\n\nSexyJson support json parse the key path\n```swift\nlet subArrayModel = SubArray.sexy_json(json, keyPath: \"subArray[0]\")\nlet subNestArray = NestArray.sexy_json(json, keyPath: \"nestArray[0][0]\")\nlet test = String.sexy_json(json, keyPath: \"nestArray[0][0].test\")\n```\n\nJson is converted into a model array object(json -\u003e [model])\n```swift\nlet arrayModel = [Model].sexy_json(json)\n```\n\nModel object array converted into the array([model] -\u003e array)\n```swift\nlet array = arrayModel.sexy_array()\n```\n\nModel object array converted into the json string([model] -\u003e json)\n```swift\nlet arrayJson = arrayModel.sexy_json()\n```\nSexyJson support model kvc( Model class implement Codable protocol )\n```swift\nlet sub = Sub.sexy_json(json, keyPath: \"sub\")\nif let modelCodingData = try? JSONEncoder().encode(modelCoding) {\n    if let modelUncoding = try? JSONDecoder().decode(Sub.self, from: modelCodingData) {\n        print(\"modelUncodingJson = \\(modelUncoding.sexy_json()!)\")\n    }\n}\n```\nPrompt\n==============\nIf you want to view the analytical results, please download this demo to check the specific usage\n\nLicenses\n==============\nAll source code is licensed under the MIT License.\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnetyouli%2Fsexyjson","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fnetyouli%2Fsexyjson","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnetyouli%2Fsexyjson/lists"}