Thursday, May 31, 2012

Best JSON library to use when developing an iPhone application?

There are a few JSON libraries/frameworks available for Objective-C developers, but I wanted to get the opinion of the resident gurus here on which one is the best, and why.

Any thoughts?

Source: Tips4all


  1. Touch JSON tends to be the best in terms of speed and unit test coverage. It's also the most widely adopted and actively developed.

  2. Another ObjC JSON library is JSONKit. It tends to be faster and use less memory than the (already mentioned) alternatives. BSD License.


  3. I've had a great experience with the API is simple and effective.

  4. I think "best" depends on what features you're interested in. If you are after a JSON parser/generator that strictly follows the JSON protocol, then you could do worse than use json-framework. (Disclaimer: I am its author.)

    It also has a features such as protection against deeply nested structures (could break the stack if left to run wild), pretty-printing the JSON output and sorting the dictionary keys. (This is useful if you want/need to make sure the key ordering in the output is the same after adding/removing entries to a dictionary. Good for automated tests, for example.)

    There is on-line documentation generated from the source available.

  5. There is a comprehensive review by JSONKit is likely to be the winner.

  6. Just to clarify for future readers, json-framework and SB-JSON is the same thing.
    Please correct me if wrong.

  7. I've been using touchJSON for a while, but noticed that it has a problem with line breaks (at least from a UITextView on iOS). Thought about trying to fix it, but bailed out since the character replacement code in TouchJSON tries to be too smart for its own good.

    Switched to json-framework. Took 10 minutes, and it handles line breaks correctly. My vote is for json-framework.

  8. I have been using the json-framework from on google code. It has worked very well for me.

  9. I've used both SBJson (mentioned above) and YAJL in projects. SBJSON is a lean and easy to use parser, I've found it easy to integrate but it's performance does fall short when compared to YAJL.

    The YAJL implementation comes with pretty effective type coercion (integers, floats, bools, etc turn in to NSNumbers), speed and event driven (sax style) parsing model. The event driven parsing has been a big win when dealing with larger data sets.



  10. I have actually just finished developing a very fast JsonSerializer (benchmarks here) which also supports Mono (The main reason why I wrote it). It doesn't use any Reflection.Emit so there is a good chance it will just run in MonoTouch. If I get the time, I plan to verify that it works in MonoTouch next week.

    Basic Example

    var customer = new Customer { Name="Joe Bloggs", Age=31 };
    var json = JsonSerializer.SerializeToString(customer);
    var fromJson = JsonSerializer.DeserializeFromString<Customer>(json);

    In the meantime you can check out these live examples which are hosted on CentOS/Nginx/Mono FastCGI.

    BTW I have now verified this and it does in-fact work with MonoTouch.

  11. I used the JSON Framework, it appeared to work alright. However at some point I was getting alloc error for SBJsonParser after I had some HTTP communication.

    Luckily I found JsonKit and my problems have been solved. Its lean and easy to use. In the end what do we need more than the ability to transform some array or dictionary in a JSON string to call your web service and to transform the webservice response from JSON notation back into an array or a dictionary!?