json-framework (now SBJSON) is EVIL

I just had an unforgivable bug due to the json-framework JSON library. It was a regression, as it previously worked well a year ago.

When I updated the library back in June, there was a massive flaw: all NSNumbers in NSDictionaries converted to JSON (a pretty common occurance) are limited to 6 significant digits.

so the long: 1234567890 becomes 1234560000
and a double: 123.4567890 becomes 123.456, 12.34567890 becomes 12.3456

Well that is totally shit, I lost the precision of a bunch of data because of this and I am not happy. Now I should have had my own tests to catch this, I accept that. But I guess I put some faith into widely-used data serialisation libraries, that they don’t lose any bloody data.

No idea if this bug is already fixed in SBJSON and I don’t really care.

I just converted my entire codebase to JSONKit. The precision is now preserved. The entire library is just two source files, and the code is actually readable. json-framework is so unnecessarily complicated I can’t even work out where my data is getting lost, so it’s no surprise the bug was introduced.


2 comments on “json-framework (now SBJSON) is EVIL

  1. Wow that’s crazy, even the Facebook iOS SDK uses SBJSON.. Is JSONKit similar in usage to SBJSON?

  2. Yeah, well I suspect this bug was short lived. But remember when we updated it back in June? We got that version T_T

    JSONKit is similar in that it parses JSON with a single command, but dissimilar in that it doesn’t fucking suck.

    JSONKit also has some API advantages:
    – it’s just 2 files – JSONKit.m and JSONKit.h. Easy!
    – It can parse and create NSData objects. No need to convert your NSData objects to/from NSString, saving some CPU time (which can add up if you’re doing a lot of JSON stuff). Of course it has NSString commands as well.
    – it doesn’t use crappy, year 2000 style Objective-C commands under the hood (so shit like the above is less likely)

    It’s basically a drop-in replacement for SBJSON. Modify your JSONRepresentation and JSONValue calls to use the ones from JSONKit, change your includes and you’re done.