{"id":20217907,"url":"https://github.com/daltoniam/jsonjoy","last_synced_at":"2025-04-10T15:44:32.443Z","repository":{"id":11369279,"uuid":"13805591","full_name":"daltoniam/JSONJoy","owner":"daltoniam","description":"Makes JSON a joy to use","archived":false,"fork":false,"pushed_at":"2015-11-02T23:24:49.000Z","size":321,"stargazers_count":56,"open_issues_count":0,"forks_count":4,"subscribers_count":7,"default_branch":"master","last_synced_at":"2024-05-08T22:31:01.223Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Objective-C","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/daltoniam.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":"2013-10-23T14:50:05.000Z","updated_at":"2021-03-10T06:21:27.000Z","dependencies_parsed_at":"2022-08-28T02:01:01.316Z","dependency_job_id":null,"html_url":"https://github.com/daltoniam/JSONJoy","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/daltoniam%2FJSONJoy","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/daltoniam%2FJSONJoy/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/daltoniam%2FJSONJoy/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/daltoniam%2FJSONJoy/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/daltoniam","download_url":"https://codeload.github.com/daltoniam/JSONJoy/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248243501,"owners_count":21071054,"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":[],"created_at":"2024-11-14T06:36:21.406Z","updated_at":"2025-04-10T15:44:32.413Z","avatar_url":"https://github.com/daltoniam.png","language":"Objective-C","readme":"JSONJoy\n=======\n\nJSONJoy is a joyful little library for iOS and Mac OSX that makes converting and mapping JSON to your objects simple. \n\nYou can read more about it here: [http://vluxe.io/json-parsing.html](http://vluxe.io/json-parsing.html)\n\n# Example #\nSo here is an JSON blob we want to parse:\n```javascript\n{\n\t\"id\" : 1\n\t\"first_name\": \"John\",\n\t\"last_name\": \"Smith\",\n\t\"age\": 25,\n\t\"address\": {\n\t\t\"id\": 1\n\t\t\"street_address\": \"21 2nd Street\",\n\t    \"city\": \"New York\",\n\t    \"state\": \"NY\",\n\t    \"postal_code\": 10021\n\t }\n\t\n}\n```\nAnd Here is our NSObjects we want to convert it to:\n\n```objective-c\n\n#import \"Address.h\"\n\n@interface User : NSObject\n\n@property(nonatomic,strong)NSNumber *objID;\n@property(nonatomic,copy)NSString *firstName;\n@property(nonatomic,copy)NSString *lastName;\n@property(nonatomic,strong)NSNumber *age;\n@property(nonatomic,strong)Address *address;\n\n@end\n\n@interface Address : NSObject\n\n@property(nonatomic,strong)NSNumber *objID;\n@property(nonatomic,copy)NSString *streetAddress;\n@property(nonatomic,copy)NSString *city;\n@property(nonatomic,copy)NSString *state;\n@property(nonatomic,strong)NSNumber *postalCode;\n\n@end\n```\nTake a bunch of error prone boilerplate code like this:\n```objective-c\n\tAFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];\n\t[manager GET:@\"http://example.com/resources.json\" parameters:nil success:^(AFHTTPRequestOperation *operation, id responseObject) \n\t{\n\t\tNSDictionary* response = responseObject;\n        User *john = [[User alloc] init];\n        john.objID = response[@\"id\"];\n        john.firstName = response[@\"first_name\"];\n        john.lastName = response[@\"last_name\"];\n        john.age = response[@\"age\"];\n\t\t//now for the address\n\t\tjohn.address = [[Address alloc] init];\n        NSDictionary* address = response[@\"address\"];\n        john.address.objID = address[@\"id\"];\n        john.address.streetAddress = address[@\"street_address\"];\n        john.address.city = address[@\"city\"];\n        john.address.state = address[@\"state\"];\n        john.address.postalCode = address[@\"postal_code\"];\n\t\t//finally!, now do work with object\n\t} failure:^(AFHTTPRequestOperation *operation, NSError *error) {\n\t    NSLog(@\"Error: %@\", error);\n\t}];\n```\nand Joyify it into this:\n```objective-c\nAFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];\n[manager GET:@\"http://example.com/resources.json\" parameters:nil success:^(AFHTTPRequestOperation *operation, id responseObject) \n{\n\tNSError *error = nil;\n\tJSONJoy *joy = [JSONJoy JSONJoyWithClass:[User class]];\n    User *john = [joy process:responseObject error:\u0026error];\n\t//do work with object\n} failure:^(AFHTTPRequestOperation *operation, NSError *error) {\n    NSLog(@\"Error: %@\", error);\n}];\n```\n\nThere is even a category on NSObject to make you be able to do a one liner like this:\n\n```objective-c\nAFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];\n[manager GET:@\"http://example.com/resources.json\" parameters:nil success:^(AFHTTPRequestOperation *operation, id responseObject) \n{\n\tUser *john = [User objectWithJoy:responseObject];\n\t//do work with object\n} failure:^(AFHTTPRequestOperation *operation, NSError *error) {\n    NSLog(@\"Error: %@\", error);\n}];\n```\nNeed to add some customize parsing? No Problem, just implement this method like the example below:\n\n```objective-c\n+(JSONJoy*)jsonMapper\n{\n    JSONJoy* mapper = [[JSONJoy alloc] initWithClass:[self class]];\n    [mapper addArrayClassMap:@\"photos\" class:[Photo class]];\n    return mapper;\n}\n```\nAll category methods call this method as well, so your objects get parsed properly.\n\n# Usage #\n\nJSONJoy works by mapping property names to JSON value names. It also supports standard rails snake case JSON names being convert to standard camel case objective-c property names. For example: \n\n```objective-c\n@property(nonatomic,copy)NSString *firstName;\n```\nsupports JSON values in the format of:\n\n```javascript\n\"first_name\": \"John\"\n\"firstName\": \"John\"\n```\n# Install #\n\nThe recommended approach for installing JSONJoy is via the CocoaPods package manager, as it provides flexible dependency management and dead simple installation.\n\nvia CocoaPods\n\nInstall CocoaPods if not already available:\n\n\t$ [sudo] gem install cocoapods\n\t$ pod setup\nChange to the directory of your Xcode project, and Create and Edit your Podfile and add JSONJoy:\n\n\t$ cd /path/to/MyProject\n\t$ touch Podfile\n\t$ edit Podfile\n\tplatform :ios, '5.0' \n\t# Or platform :osx, '10.8'\n\tpod 'JSONJoy'\n\nInstall into your project:\n\n\t$ pod install\n\t\nOpen your project in Xcode from the .xcworkspace file (not the usual project file)\n\nVia git\njust add JSONJoy as a git submodule\n\n# Requirements #\n\nJSONJoy requires at least iOS 5/Mac OSX 10.8 or above.\n\n# License #\n\nJSONJoy is license under the Apache License.\n\n# Contact #\n\n### Dalton Cherry ###\n* https://github.com/daltoniam\n* http://twitter.com/daltoniam\n\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdaltoniam%2Fjsonjoy","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdaltoniam%2Fjsonjoy","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdaltoniam%2Fjsonjoy/lists"}