JSON or SOAP (XML)? JSON or SOAP (XML)? objective-c objective-c

JSON or SOAP (XML)?


JSON has several advantages over XML. Its a lot smaller and less bloated, so you will be passing much less data over the network - which in the case of a mobile device will make a considerable difference.

Its also easier to use in javascript code as you can simply pass the data packet directly into a javascript array without any parsing, extracting and converting, so it is much less CPU intensive too.

To code with it, instead of an XML library, you will want a JSON library. Dates are handled as you would with XML - encode them to a standard, then let the library recognise them. (eg here's a library with a sample with dates in it)

Here's a primer.


Ah, the big question: JSON or XML?

In general, I would prefer XML only when I need to pass around a lot of text, since XML excels at wrapping and marking up text.

When passing around small data objects, where the only strings are small (ids, dates, etc.), I would tend to use JSON, as it is smaller, easier to parse, and more readable.

Also, note that even if you choose XML, that does not by any means mean you need to use SOAP. SOAP is a very heavy-weight protocol, designed for interoperability between partners. As you control both the client and server here, it doesn't necessarily make sense.


Consider how you'd be consuming the results on the iPhone. What mechansim would you use to read the web service response? NSXMLParser?

How you consume the data would have the biggest impact on how your serve it.

Are JSON and SOAP your only options? What about RESTful services?

Take a look at some big players on the web that have public APIs that are accessible by iPhone clients:

Twitter APIFriendFeed API

Also, review the following related articles: