All Projects → hyperoslo → Minced

hyperoslo / Minced

Licence: other
Convert JSON keys to camelCase

Programming Languages

objective c
16641 projects - #2 most used programming language
ruby
36898 projects - #4 most used programming language

Minced

CI Status Version License Platform

Mincing is a food preparation technique in which food ingredients are finely divided into uniform pieces.

Minced converts JSON keys to camelCase an adds support for replacement of JSON null values with empty strings.

This is especially useful as a workaround for avoiding crashes due to null values when using Realm. More info: Issue #628

Usage

// Converts all the keys in the JSON to camelCase
- (id)minced_JSONKeys;
- (NSArray *)minced_JSONObjectsKeys;
- (NSDictionary *)minced_JSONObjectKeys;

// Converts all the keys in the JSON to camelCase and replaces null values with an empty string
- (id)minced_JSONKeysWithNonnulls;
- (NSArray *)minced_JSONObjectsKeysWithNonnulls;
- (NSDictionary *)minced_JSONObjectKeysWithNonnulls;

Example

JSON

[
  {
    "created_at":null,
    "updated_at":"2015-03-11",
    "window":{
      "title":null,
      "name":"hyper_window"
    }
  },
  {
    "created_at":null,
    "updated_at":"2015-03-12",
    "panel":{
      "title":null,
      "name":"hyper_panel"
    }
  }
]

Code

NSArray *mincedJSON = [JSON minced_JSONObjectsKeysWithNonnulls];

// Realm
RLMRealm *realm = [RLMRealm defaultRealm];
[realm beginWriteTransaction];
[self createOrUpdateInDefaultRealmWithObject:mincedJSON];
[realm commitWriteTransaction];

Minced JSON

[
  {
    "createdAt":"",
    "updatedAt":"2015-03-11",
    "window":{
      "title":"",
      "name":"hyper_window"
    }
  },
  {
    "createdAt":"",
    "updatedAt":"2015-03-12",
    "panel":{
      "title":"",
      "name":"hyper_panel"
    }
  }
]

Installation

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

pod 'Minced'

Author

Hyper Interaktiv AS, [email protected]

License

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

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].