{"id":16720050,"url":"https://github.com/musjoy/swift-mjmodel","last_synced_at":"2026-05-14T01:39:57.194Z","repository":{"id":56920560,"uuid":"203295609","full_name":"Musjoy/Swift-MJModel","owner":"Musjoy","description":"MJModel is a framework in swift which allows you to easily convert model to json string or json string to model.","archived":false,"fork":false,"pushed_at":"2019-08-23T09:41:42.000Z","size":92,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-02-22T06:02:19.748Z","etag":null,"topics":["deserialization","json","json-string","mirror","protocol","serialization","swift"],"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/Musjoy.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":"2019-08-20T03:51:04.000Z","updated_at":"2019-08-26T03:44:57.000Z","dependencies_parsed_at":"2022-08-21T04:20:20.720Z","dependency_job_id":null,"html_url":"https://github.com/Musjoy/Swift-MJModel","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Musjoy%2FSwift-MJModel","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Musjoy%2FSwift-MJModel/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Musjoy%2FSwift-MJModel/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Musjoy%2FSwift-MJModel/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Musjoy","download_url":"https://codeload.github.com/Musjoy/Swift-MJModel/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243725525,"owners_count":20337666,"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":["deserialization","json","json-string","mirror","protocol","serialization","swift"],"created_at":"2024-10-12T22:05:29.342Z","updated_at":"2026-05-14T01:39:57.157Z","avatar_url":"https://github.com/Musjoy.png","language":"Swift","funding_links":[],"categories":[],"sub_categories":[],"readme":"# MJModel\n\nMJModel is a framework which allows you to easily convert model to json string or json string to model.\n\nMJModel supports class and struct, and no need to inherit from NSObject. By replacing KVC in NSObject, it directly operate memory to get or set values. And it use Mirror in Swift to get all properties in model.\n\nMJModel is defined as a protocol, so you can use it simply just like protocol. Only one extension of the existed model can do the trick. \n\n[![CI Status](https://img.shields.io/travis/Musjoy/Swift-MJModel.svg?style=flat)](https://travis-ci.org/Musjoy/Swift-MJModel)\n[![codecov](https://codecov.io/gh/Musjoy/Swift-MJModel/branch/master/graph/badge.svg)](https://codecov.io/gh/Musjoy/Swift-MJModel)\n[![Version](https://img.shields.io/cocoapods/v/MJModel.svg?style=flat)](https://cocoapods.org/pods/MJModel)\n[![License](https://img.shields.io/cocoapods/l/MJModel.svg?style=flat)](https://cocoapods.org/pods/MJModel)\n[![Platform](https://img.shields.io/cocoapods/p/MJModel.svg?style=flat)](https://cocoapods.org/pods/MJModel)\n[![Carthage compatible](https://img.shields.io/badge/Carthage-compatible-4BC51D.svg?style=flat)](https://github.com/Carthage/Carthage)\n[![Gitter](https://badges.gitter.im/Musjoy/DBModel.svg)](https://gitter.im/Musjoy/DBModel?utm_source=badge\u0026utm_medium=badge\u0026utm_campaign=pr-badge)\n\n## Requirements\n\n- iOS 8.0+ / Mac OS X 10.9+\n- Xcode 11.0+\n- Swift 5.0+\n\n## Installation\n\n### [CocoaPods](https://cocoapods.org/) :\n\n```ruby\npod 'MJModel'\n```\n\n### [Carthage](https://github.com/Carthage/Carthage) :\n```\ngithub \"Musjoy/Swift-MJModel\" \"master\"\n```\n\n### [Swift Package Manager](https://github.com/apple/swift-package-manager) :\nAdd the following to your Package.swift file's dependencies:\n```swift\ndependencies: [\n    .package(url: \"https://github.com/Musjoy/Swift-MJModel.git\", from: \"0.1.0\"),\n]\n```\n\n## Usage\n\n### Import\n\n```swift\nimport MJModel\n```\n\n### Model To JSON String\n\n```swift\nclass BaseClass : Model {\n    var name : String?\n    var age : Int?\n    \n    required init() {}\n}\n\nlet model = BaseClass()\nmodel.name = \"string\"\nmodel.age = 1\n\nprint(model.toDictionary())\nprint(model.toJSONString()!)\n```\n### JSON String To Model\n\n```swift\nlet jsonString = \"{\\\"name\\\":\\\"string\\\",\\\"age\\\":1}\"\nlet modelResult = BaseClass.initWith(jsonString)!\nprint(modelResult.name!)\nprint(modelResult.age!)\n```\n\n### Extend Other\n\n```swift\nstruct ExtendOtherStruct {\n    var name : String?\n    var age : Int?\n}\n\nextension ExtendOtherStruct : Model {}\n\nvar model = ExtendOtherStruct()\nmodel.name = \"string\"\nmodel.age = 1\n    \nlet jsonString = model.toJSONString();\nlet modelResult = ExtendOtherStruct.initWith(jsonString!)!\nprint(jsonString!)\nprint(modelResult.name!)\nprint(modelResult.age!)\n```\n\n## Author\n\nraymond-hl, Raymond.huang@musjoy.com\n\n## License\n\nMJModel 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%2Fmusjoy%2Fswift-mjmodel","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmusjoy%2Fswift-mjmodel","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmusjoy%2Fswift-mjmodel/lists"}