Parse a JSON response from a REST API directly into your existing Objective-C model objects without writing repetitive boilerplate code.
Convert nested JSON structures containing arrays or child objects into a fully typed model hierarchy in a single call.
Serialize an Objective-C model object back to an NSDictionary for sending data to an API.
Map JSON keys that use underscore naming to camelCase property names in your iOS model automatically.
MJExtension is a library for iOS and macOS developers that handles the translation between JSON data and Objective-C model objects. JSON is the standard format that web servers send data in, and model objects are the data structures that apps use internally to represent things like a user profile, a post, or a product. Normally, converting between them requires writing a lot of repetitive code. MJExtension automates that process. The key design goal is that it does not require you to change your existing model classes in any way. There is no base class to inherit from, no annotations to add to your properties, and no configuration files to maintain. You point MJExtension at a dictionary of JSON data and a model class, and it fills in the model's fields by matching the JSON keys to the property names. The library handles a range of conversion scenarios beyond simple flat objects. It can convert nested models, meaning a JSON object that contains another object inside it. It can convert arrays of models from JSON arrays. It supports converting model objects back into JSON dictionaries as well, so the conversion goes both directions. It also handles some common type mismatches, such as converting a date string into an actual date object, or treating a string value as a boolean. For cases where the JSON key names do not match the model property names, MJExtension lets you define a mapping so it knows how to connect them. It also has built-in support for converting camelCase property names to underscore-separated key names, which is a common difference between server and client naming conventions. The README is written in both English and Chinese. Installation is available through CocoaPods, Carthage, Swift Package Manager, or by manually copying the source files into a project. The library also works with Swift projects through Objective-C bridging, though the README notes that pure-Swift projects may prefer a separate Swift-native library called KakaJSON instead.
← codermjlee on gitmyhub — every repo by this author, as a profile.
Verify against the repo before relying on details.