DZJSONKit icon indicating copy to clipboard operation
DZJSONKit copied to clipboard

iOS Titanium module for insanely rapid JSON data conversions.

DZJSONKit

DZJSONKit is a Titanium module for parsing JSONData or JSONStrings and stringify-ing Objects. It it based on JSONKit by John Engelhart, which, in comparison to SBJSON, which is shipped with Titanium, is insanely fast. I highly recommend using this module whenever interacting with JSON in your titanium app.

This module is for iOS only. It has been tested on iOS5.1 and iOS6.

TEST HARNESS EXAMPLE FOR DZJSONKit

The example directory contains a skeleton application test harness that can be used for testing and providing an example of usage for DZJSONKit.

INSTALL DZJSONKit

  1. Run build.py which creates your distribution
  2. cd to /Library/Application Support/Titanium
  3. copy this zip file into the folder of your Titanium SDK

REGISTER YOUR MODULE

Register your module with your application by editing tiapp.xml and adding your module. Example:

com.dzjsonkit

When you run your project, the compiler will know automatically compile in your module dependencies and copy appropriate image assets into the application.

USING YOUR MODULE IN CODE

To use your module in code, you will need to require it.

var kit = require('com.DZJSONKit');

Once you have included the module in your code, the module exposes certain methods for interacting with JSON.

/* To parse a response JSON String:  */

var objectFromString = kit.parse(jsonString);



/* To stringify a valid JSON Object */

var stringFromObject = kit.stringify(jsonObject);

Version Update notes

v0.3

  • Using GCD to perform parsing and stringifying of data on a background priority thread instead of the main UI thread. This speeds up everything. (Fixes #1)
  • Removed parseData method (rarely or never used).

v0.2

  • Non-JSON format strings, when parsed, return null.
  • Searlizing JSON Data now returns a string as opposed to a TiBlob, as done in the previous version
  • Renamed methods: parseString to parse and stringifyObject to stringify

v0.1 Initial launch

Notes

  • It it important to note that the JSONKit library works only with UTF-8 encoded data. If your data is not UTF-8 encoded, or you suspect so, kindly encode it before parsing.
  • JSONKit is dual licensed under either the terms of the BSD License, or alternatively under the terms of the Apache License, Version 2.0. Copyright © 2011, John Engelhart. Kindly include the required licenses in your app if using JSONKit.
  • DZJSONKit is published as a no-license module. However, do note that I shall not be responsible for any inconsistencies or damages caused by the inclusion and/or usage of the module, as a whole or in parts.

An excerpt from the README docs of JSONKit

A Very High Performance Objective-C JSON Library

UPDATE: (2011/12/18) The benchmarks below were performed before Apples [NSJSONSerialization][NSJSONSerialization] was available (as of Mac OS X 10.7 and iOS 5). The obvious question is: Which is faster, [NSJSONSerialization][NSJSONSerialization] or JSONKit? According to this site, JSONKit is faster than [NSJSONSerialization][NSJSONSerialization]. Some quick "back of the envelope" calculations using the numbers reported, JSONKit appears to be approximately 25% to 40% faster than [NSJSONSerialization][NSJSONSerialization], which is pretty significant.

Parsing Serializing
Deserialize from JSON Serialize to JSON
23% Faster than Binary .plist ! 549% Faster than Binary .plist !