{"id":21302603,"url":"https://github.com/kevin-lyn/ditto","last_synced_at":"2025-10-15T20:37:11.756Z","repository":{"id":56908654,"uuid":"67569722","full_name":"kevin-lyn/Ditto","owner":"kevin-lyn","description":"Serialize swift object to JSON object.","archived":false,"fork":false,"pushed_at":"2017-08-12T10:35:10.000Z","size":47,"stargazers_count":6,"open_issues_count":0,"forks_count":1,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-07-26T21:29:44.794Z","etag":null,"topics":["ios","json","macos","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/kevin-lyn.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":"2016-09-07T03:46:31.000Z","updated_at":"2019-06-16T18:34:11.000Z","dependencies_parsed_at":"2022-08-21T02:20:56.572Z","dependency_job_id":null,"html_url":"https://github.com/kevin-lyn/Ditto","commit_stats":null,"previous_names":["kevin0571/ditto"],"tags_count":5,"template":false,"template_full_name":null,"purl":"pkg:github/kevin-lyn/Ditto","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kevin-lyn%2FDitto","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kevin-lyn%2FDitto/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kevin-lyn%2FDitto/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kevin-lyn%2FDitto/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/kevin-lyn","download_url":"https://codeload.github.com/kevin-lyn/Ditto/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kevin-lyn%2FDitto/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":279111652,"owners_count":26106084,"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-15T02:00:07.814Z","response_time":56,"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","json","macos","serialization"],"created_at":"2024-11-21T15:56:56.477Z","updated_at":"2025-10-15T20:37:11.735Z","avatar_url":"https://github.com/kevin-lyn.png","language":"Swift","funding_links":[],"categories":[],"sub_categories":[],"readme":"# \u003cimg src=\"https://cloud.githubusercontent.com/assets/1491282/18335864/2b8501d6-75b5-11e6-8bf5-276fe60792b0.png\" height=\"26\" width=\"24\"\u003e Ditto ![CI Status](https://travis-ci.org/kevin0571/Ditto.svg?branch=master) ![Version](http://img.shields.io/cocoapods/v/Ditto-Swift.svg?style=flag) ![Carthage](https://img.shields.io/badge/Carthage-compatible-brightgreen.svg) ![Swift Pacakge Manager](https://img.shields.io/badge/Swift%20Package%20Manager-compatible-brightgreen.svg) ![License](https://img.shields.io/cocoapods/l/Ditto-Swift.svg?style=flag)\nDitto allows you to serialize your swift object to JSON object compatible dictionary.\n\n## Features\n- Customizable mapping.\n- Auto mapping with frequently used mapping style.\n- Custom type convertible supported.\n- Nested serializable.\n\n## Requirements\n- Xcode 8.0+\n- Swift 3.0\n\n## Usage\n\n**CocoaPods**\n```ruby\npod 'Ditto-Swift'\n```\n\n**Carthage**\n```ruby\ngithub \"kevin0571/Ditto\"\n```\n\n**Swift Package Manager**\n```ruby\ndependencies: [\n    .Package(url: \"https://github.com/kevin0571/Ditto.git\", majorVersion: 1)\n]\n```\n\n### Overview\n```swift\nimport Ditto\n\nstruct ExampleStruct {\n    let string = \"string\"\n    let anotherString = \"anotherString\"\n    let int = 1\n    let url = URL(string: \"https://github.com\")\n}\n\nextension ExampleStruct: Serializable {\n    func serializableMapping() -\u003e Mapping {\n        return [\n            \"string\": \"str\",\n            \"int\": \"integer\",\n            \"url\": \"url\"\n        ]\n    }\n}\n\n// Serialize ExampleStruct\nlet exampleStruct = ExampleStruct()\n\n// To Dictionary\nlet jsonObject: JSONObject = exampleStruct.serialize()\nlet jsonArray: [JSONObject] = [exampleStruct, exampleStruct].serialize()\n/*\n \"jsonObject\" will be a dictionary with content:\n [\n    \"str\": \"string\",\n    \"integer\": 1,\n    \"url\": \"https://github.com\"\n ]\n note that \"anotherString\" is not being serialized,\n becuase mapping of \"anotherString\" is not defined in \"serializableMapping\".\n */\n \n// To String\nlet jsonObjectString: String = exampleStruct.serialize()\n\n// To Data\nlet jsonObjectData: Data = exampleStruct.serialize()\n```\n\n### Auto Mapping\nAvailable auto mapping styles: **lowercaseSeparatedByUnderScore**, **lowercase**, **lowerCamelCase**, **upperCamelCase**\n```swift\nextension ExampleStruct: Serializable {\n    func serializableMapping() -\u003e Mapping {\n        return AutoMapping.mapping(\n            for: self, \n            style: .lowercaseSeparatedByUnderScore\n        )\n    }\n}\n\n// Serialize ExampleStruct with auto mapping\nlet exampleStruct = ExampleStruct()\nlet jsnObject = exampleStruct.serialize()\n/*\n \"jsonObject\" will be a dictionary with content:\n [\n    \"string\": \"string\",\n    \"another_string\": \"anotherString\",\n    \"int\": 1,\n    \"url\": \"https://github.com\"\n ]\n */\n```\n\n### Custom Type Convertible\n```swift\nclass CustomClass {\n    let string = \"string\"\n    let int = 1\n    private var converted: String {\n        return \"Converted to: \\(string), \\(int)\"\n    }\n}\n\nextension CustomClass: Convertible {\n    func convert() -\u003e Any {\n        return converted\n    }\n}\n\nstruct ExampleStruct {\n    let customClass = CustomClass()\n}\n\nextension ExampleStruct: Serializable {\n    func serializableMapping() -\u003e Mapping {\n        return AutoMapping.mapping(\n            for: self, \n            style: .lowercaseSeparatedByUnderScore\n        )\n    }\n}\n\n// Serialize ExampleStruct\nlet exampleStruct = ExampleStruct()\nlet jsonObject = exampleStruct.serialize()\n/*\n \"jsonObject\" will be a dictionary with content:\n [\n    \"custom_class\": \"Converted to: string, int\"\n ]\n */\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkevin-lyn%2Fditto","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkevin-lyn%2Fditto","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkevin-lyn%2Fditto/lists"}