{"id":15293585,"url":"https://github.com/damonthecricket/my-json","last_synced_at":"2026-05-08T08:03:14.874Z","repository":{"id":62447344,"uuid":"90287713","full_name":"damonthecricket/my-json","owner":"damonthecricket","description":"Simple Swift JSON library.","archived":false,"fork":false,"pushed_at":"2018-03-20T14:28:56.000Z","size":2609,"stargazers_count":0,"open_issues_count":1,"forks_count":1,"subscribers_count":0,"default_branch":"master","last_synced_at":"2025-12-08T15:11:04.289Z","etag":null,"topics":["apple","code","framework","ios","json","library","macos","myjson","parsing","swift","swift-3","swift3","tvos"],"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/damonthecricket.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-04T16:54:59.000Z","updated_at":"2018-03-20T14:28:57.000Z","dependencies_parsed_at":"2022-11-01T23:02:16.050Z","dependency_job_id":null,"html_url":"https://github.com/damonthecricket/my-json","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"purl":"pkg:github/damonthecricket/my-json","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/damonthecricket%2Fmy-json","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/damonthecricket%2Fmy-json/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/damonthecricket%2Fmy-json/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/damonthecricket%2Fmy-json/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/damonthecricket","download_url":"https://codeload.github.com/damonthecricket/my-json/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/damonthecricket%2Fmy-json/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":32772048,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-08T02:36:36.067Z","status":"ssl_error","status_checked_at":"2026-05-08T02:36:07.210Z","response_time":54,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"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":["apple","code","framework","ios","json","library","macos","myjson","parsing","swift","swift-3","swift3","tvos"],"created_at":"2024-09-30T16:50:04.193Z","updated_at":"2026-05-08T08:03:14.821Z","avatar_url":"https://github.com/damonthecricket.png","language":"Swift","funding_links":[],"categories":[],"sub_categories":[],"readme":"# MYJSON\n[![Version](https://img.shields.io/github/release/damonthecricket/my-json.svg)](https://github.com/damonthecricket/my-json/releases)\n[![Travis CI](https://travis-ci.org/damonthecricket/my-json.svg?branch=master)](https://travis-ci.org/damonthecricket/my-json)\n![CocoaPods](https://img.shields.io/cocoapods/v/MYJSON.svg)\n[![Carthage compatible](https://img.shields.io/badge/Carthage-compatible-4BC51D.svg?style=flat)](https://github.com/Carthage/Carthage)\n[![GitHub license](https://img.shields.io/badge/license-MIT-lightgrey.svg)](https://raw.githubusercontent.com/damonthecricket/my-json/master/LICENSE)\n![Platform](https://img.shields.io/badge/platforms-iOS%208.0+%20%7C%20macOS%2010.10+%20%7C%20tvOS%209.0+%20%7C%20watchOS%202.0+-333333.svg)\n\n![MYJSON](https://github.com/damonthecricket/my-json/blob/master/my-json-lib.jpg)\nSwift JSON framework.\n\nMYJSON is a simple Swift library to convert JSON to strongly typed objects.\n\n1. [Features](#features)\n2. [Installation](#installation)\n3. [Requirements](#requirements)\n4. [Usage](#usage)\n    - [JSON](#json)\n    - [Deserializing](#deserializing)\n    - [Serializing](#serializing)\n    \n\n\n### Features\n\n- Mapping JSON to objects.\n\n- Mapping objects to JSON.\n\n- Custom transformations.\n\n- Easy and safe using.\n\n### Installation\n\n- #### [CocoaPods](http://cocoapods.org/)\n\n  ```ruby\n  use_frameworks!\n  \n  pod 'MYJSON'\n  ```\n\n- #### [Carthage](https://github.com/Carthage/Carthage)\n\n  ```\n  github \"damonthecricket/my-json\"\n  ```\n\n- #### [Git](https://git-scm.com/)\n\n  ```\n  $ git submodule add https://github.com/damonthecricket/my-json.git\n  ```\n- #### Manually\n\n  - Copy MYJSON to the root of your project.\n  \n  - Add it in file inspector of your project.\n  \n  - Go to Targets -\u003e Add MYJSON to Embedded Binaries.\n  \n### Requirements\n  \n - iOS 8.0+  |  macOS 10.10+  |  tvOS 9.0+  |  watchOS 2.0+.\n \n - Xcode 8.\n \n - Swift 3.\n \n### Usage\n\n#### JSON\n\n##### Initialization\n```MYJSON``` is ```enum```, which represents JSON in two variations. ```MYJSON``` takes on value ```dictionary``` or ```array of dictionaries```.\n\nYou can initialize ```MYJSON``` in the manner described below:\n\n```swift\nimport MYJSON\n\nlet rawJSON: MYSJONType = [\n    \"id\": \"sdfsf34324sdfdhg1\"\n    \"index\": 98451\n    \"first name\": \"Damon\"\n    \"last name\": \"Cricket\"\n]\n\nlet json: MYJSON = MYJSON(rawValue: rawJSON)\n\nlet jsonArray: MYJSON = MYJSON(rawValue: rawJSON)\nswitch json: {\n    case .value(let json):\n       // ...\n       // Code\n       // ...\n    default:\n       break\n}   \n```\n\nand\n\n```swift\nimport MYJSON\n\nlet rawJSONArray: MYSJONType = [\n    [\"id\": \"sdfsf34324sdfdhg1\",\n     \"index\": 98451,\n     \"first name\": \"Damon\",\n     \"last name\": \"Cricket\"],\n     \n    [\"id\": \"fkgfg34kfg\",\n     \"index\": 1234,\n     \"first name\": \"Zee\",\n     \"last name\": \"Gor\"]\n]\n\nlet jsonArray: MYJSON = MYJSON(rawValue: rawJSONArray)\nswitch jsonArray: {\n    case .array(let jsonArray):\n       // ...\n       // Code\n       // ...\n    default:\n       break\n}   \n```\n\nor \n\n```swift\nimport MYJSON\n\nif let json = try? JSONSerialization.allowFragmentsJSON(with: data) {\n      // ...\n      // Code\n      // ...\n}\n```\n\n1. In first case ```MYJSON``` instance is ```.value(let json)```, where value associated with ```JSON``` instance (```dictionary```, or ```MYJSONType```).\n\n2. In second case ```MYJSON``` instance is ```.array(let array)```, where value associated with ```JSON array``` (or ```MYJSONArrayType```).\n\n3. In third case ```MYJSON``` instance initialized from raw ```JSON data``` and hold associated value.\n\n\u003e *Note*: ```MYJSON init(rawValue: Any)``` takes only two type of input parameter - ```MYJSONType``` (```[String: Any]```) or ```MYJSONArrayType``` (```[[String: Any]]```), otherwise initializer returns empty MYJSON.\n\n##### Properties\n```MYJSON``` has a useful properties and functions. For example, you can you can check wheter instance is ```dictionary``` or ```array of dictionaries```:\n```swift\nimport MYJSON\n\nif json.isDictionary {\n    // Code\n}\n\nif json.isArray {\n    // Code\n}\n\n```\nAlso you can access to JSON associated value.\nFor ```dictionary```:\n```swift\nimport MYJSON\n\nvar id: String = json[\"id\"]\n```\nFor ```array of dictionaries```:\n```swift\nimport MYJSON\n\nvar json: MYJSONType = jsonArray[0]\n```\n\n#### Deserializing\n\nLet's say we have a simple account class and gender enum:\n```swift\n  \n  enum Gender: String {\n    case male = \"male\"\n    case female = \"female\"\n  }\n  \n  class Account {\n    var id: String = \"\"    \n    var index: UInt = 0    \n    var balance: String = \"\"\n    var age: UInt = 0    \n    var gender: GenderTestEnum = .male\n    var name: String = \"\"\n  }\n```\nand JSON like this:\n\n```swift\n import MYJSON\n \n let testJSON: MYJSONType =[\n        \"id\": \"590c8ed16470876ae51b4bd8\",                 \n        \"index\": 0,\n        \"guid\": \"c0fcc2d9-415d-415f-a081-d9d9aedc4b9c\",\n        \"isActive\": false,\n        \"balance\": \"$1,897.29\",\n        \"picture\": \"http://placehold.it/32x32\",\n        \"age\": 32,\n        \"eyeColor\": \"green\",\n        \"name\": \"Fanny Hughes\",\n        \"gender\": \"female\",\n        \"company\": \"ZENTILITY\"\n]\n```\nWe can add JSON deserialization to this class easily:\n```swift\n  import MYJSON\n  \n  extension Account: MYJSONDeserizlizable {\n      init(json: MYJSON) {\n            id \u003c- json[\"id\"]\n            index \u003c- json.number(forKey: \"index\").uintValue\n            balance \u003c- json[\"balance\"]\n            age \u003c- json.number(forKey: \"index\").uintValue\n            gender \u003c- json[\"gender\"]\n            name \u003c- json[\"name\"]\n      }\n  }\n```\n\nand after that we can deserialize JSON into Account instance very simple and easy:\n```swift\nimport MYJSON\n\nlet json = MYJSON(rawValue: testJSON)\nlet account: Account = Account.self \u003c- json\n```\nor in case of ```array of dictionaries```:\n```swift\nimport MYJSON\n\nlet jsonArray = MYJSON(rawValue: testJSON)\nlet account: [Account] = Account.self \u003c- jsonArray\n```\n#### Serializing\nAlso MYJSON lib has a feature to serialize. For that we should to implement ```MYJSONSerizlizable protocol```, and specifically implement required protocol properry ```var json: MYJSON```.\nLet's consider simple class Friend:\n```swift\nclass Friend {\n    var id: UInt = 0\n    var name: String = \"\"\n}\n```\nWe can add JSON serialization to this class:\n```swift\nimport MYJSON\n\nextension Friend: MYJSONSerizlizable {\n    var json: MYJSON {\n        return MYJSON(rawValue: [\"id\": id, \"name\": name])\n    }\n}\n```\nNow we can serialize Friend instance to ```MYJSON```:\n```swift\nimport MYJSON\n\nlet friend: Friend = \u003c...\u003e\nlet json = friend.json\n```\nThen we have opportunity to serialize ```MYJSON``` instance to ```Data``` using JSONSerialization extension:\n```swift\nimport MYJSON\n\nif let data = try? JSONSerialization.prettyPrintedData(withJSON: json) {\n    // Code\n}\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdamonthecricket%2Fmy-json","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdamonthecricket%2Fmy-json","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdamonthecricket%2Fmy-json/lists"}