Latest 0.2.7
Homepage https://github.com/buranmert/MBJSONMapper
License MIT
Platforms ios 8.0
Frameworks Foundation
Authors

CI Status
Version
License
Platform

Why yet another JSON<>Object library???

I looked at other libraries but none of them seemed simple/minimal enough to me. The whole idea of this library is being as small as possible:

  1. 2 public headers
    1. 1 protocol
    2. 1 adapter
  2. Total line count of .m files: 186

Usage

Basic usage

JSON

{
    "middleName" = "Hatice"
    "name" = "John"
    "surname" = "Appleseed"
}

TestDataModel.h

#import <MBJSONMapper/MBJSONSerializable.h>

@interface TestDataModel : NSObject <MBJSONSerializable>

@property (nonatomic, copy, readonly) NSString *name;
@property (nonatomic, copy, readonly) NSString *middleName;
@property (nonatomic, copy, readonly) NSString *surname;

@end

TestDataModel.m

@implementation TestDataModel
// Nothing!
@end

Advanced usage

JSON

{
    "isItTrue" = 1
    "middleName" = "Hatice"
    "name" = "John"
    "surname" = "Appleseed"
    "nestedModel" =     {
        "middleName" = ""
        "name" = "Nested"
        "surname" = "John"
    }
    "nestedModels" =     (
                {
            "middleName" = "1"
            "name" = "John"
            "surname" = "Dupont"
        },
                {
            "middleName" = "2"
            "name" = "John"
            "surname" = "Dupont"
        },
                {
            "middleName" = "3"
            "name" = "John"
            "surname" = "Dupont"
        }
    )
}

TestDataModel.h

#import <MBJSONMapper/MBJSONSerializable.h>

@interface TestDataModel : NSObject <MBJSONSerializable>

@property (nonatomic, readonly) BOOL isItTrue;

@property (nonatomic, copy, readonly) NSString *name;
@property (nonatomic, copy, readonly) NSString *surname;
@property (nonatomic, copy, readonly) NSString *secondName;

@property (nonatomic, copy, readonly) NSString *nestedModelName;

@property (nonatomic, copy, readonly) TestDataModel *nestedModel;
@property (nonatomic, copy, readonly) NSArray<TestDataModel*> *nestedModels;

@end

TestDataModel.m

@implementation TestDataModel

- (NSDictionary<NSString*, NSString*> *)keyPropertyMappingDictionary {
    return @{@"nestedModel.name": NSStringFromSelector(@selector(nestedModelName)),
             @"middleName":  NSStringFromSelector(@selector(secondName))};
}

- (NSDictionary<NSString*, Class> *)keyClassMappingDictionary {
    return @{NSStringFromSelector(@selector(nestedModel)): [TestDataModel class],
             NSStringFromSelector(@selector(nestedModels)): [TestDataModel class]};
}

@end

That’s all folks!

Example

To run the example project, clone the repo, and run pod install from the Example directory first.

Requirements

Installation

MBJSONMapper is available through CocoaPods. To install
it, simply add the following line to your Podfile:

pod "MBJSONMapper"

Author

Mert Buran, [email protected]

License

MBJSONMapper is available under the MIT license. See the LICENSE file for more info.

Latest podspec

{
    "name": "MBJSONMapper",
    "version": "0.2.7",
    "summary": "Light-weight JSON to and from Object mapper",
    "description": "There are plenty of JSON mapping libraries but most of them are not light enough. I tried to do it as simple as it can be",
    "homepage": "https://github.com/buranmert/MBJSONMapper",
    "license": {
        "type": "MIT",
        "file": "LICENSE"
    },
    "authors": {
        "Mert Buran": "[email protected]"
    },
    "source": {
        "git": "https://github.com/buranmert/MBJSONMapper.git",
        "tag": "0.2.7"
    },
    "social_media_url": "https://twitter.com/lazymanandbeard",
    "platforms": {
        "ios": "8.0"
    },
    "source_files": [
        "MBJSONMapper/Classes/{MBJSONMapper,NSObject+MBJSONMapperExtension}.{m,h}",
        "MBJSONMapper/Classes/MBJSONSerializable.h"
    ],
    "public_header_files": "MBJSONMapper/Classes/{MBJSONMapper,MBJSONSerializable}.h",
    "frameworks": "Foundation"
}

Pin It on Pinterest

Share This