Swift 101: JSON or XML?

Hi,

I'm about to develop my first non-trivial (for me) Swift 3 app. It will retrieve data from a web server and present it on an iOS device.

I would welcome guidance regarding whether I should use JSON or XML to store the data on the web server? The effort to generate either format will be similar so my real decision driver is on the client side. Volume will typically be 100-250 "records" per request with each record comprising 5-10 text fields.

I don't want to pull in any third-party components but stay entirely Apple.

TIA,

Roy

Either should be fine, but in my experience JSON is a lot easier to work with due as compared to XML since JSONSerialization being simpler than XMLParser.

Saagar Jha

···

On Feb 3, 2017, at 5:00 AM, Roy Henderson via swift-users <swift-users@swift.org> wrote:

Hi,

I'm about to develop my first non-trivial (for me) Swift 3 app. It will retrieve data from a web server and present it on an iOS device.

I would welcome guidance regarding whether I should use JSON or XML to store the data on the web server? The effort to generate either format will be similar so my real decision driver is on the client side. Volume will typically be 100-250 "records" per request with each record comprising 5-10 text fields.

I don't want to pull in any third-party components but stay entirely Apple.

TIA,

Roy
_______________________________________________
swift-users mailing list
swift-users@swift.org
https://lists.swift.org/mailman/listinfo/swift-users

Technically there is little to chose one over the other. I find working with JSON on Swift is somewhat easier than XML however, and that should not be a minor consideration.

However, moving forward it seems that JSON will be more widely used and basing your comms on that is likely a very good idea. For instance, there are any number of modern databases who's native format is JSON, and you're more likely to end up on one of them than the (generally older) servers that use XML. Additionally, I find it reasonable to suggest that in the future there will be much more JSON code and knowledge to draw on from the community.

Probably JSON. It’s usually a lot easier for clients to parse than XML. If you’re thinking about web clients, JSON is the most natural data format for JavaScript to work with. Another issue is that even generating XML can be a minefield unless you have a solid library to do it for you — I used to work on an RSS/Atom reader, and encountered so many news feeds that generated broken XML due to ignoring subtleties of quoting and name spacing. And parsing broken XML is even more difficult than parsing correct XML, because a regular XML parser is required to reject it entirely.

(But XML does have the advantage of a richer data model, with names to identify different elements, which makes it more self-describing; in JSON you often have to have either an informal schema describing what different objects represent, or explicitly add a property like “type”: to identify an object. This actually helps a lot if you’re parsing to native objects, since you can easily set up a mapping from XML element names to native classes.)

—Jens

···

On Feb 3, 2017, at 5:00 AM, Roy Henderson via swift-users <swift-users@swift.org> wrote:

I would welcome guidance regarding whether I should use JSON or XML to store the data on the web server? The effort to generate either format will be similar so my real decision driver is on the client side.

I do not think there is a ‘best’ answer.

I would go with JSON though.

Apple’s JSON solution is fast, but it has some minor limitations and usability is not “up there”.

Then again there are third party solutions, for example my own SwifterJSON single-class framework that you can download from github. :-)

Regards,
Rien

Site: http://balancingrock.nl
Blog: http://swiftrien.blogspot.com
Github: Balancingrock (Rien) · GitHub
Project: http://swiftfire.nl

···

On 03 Feb 2017, at 14:00, Roy Henderson via swift-users <swift-users@swift.org> wrote:

Hi,

I'm about to develop my first non-trivial (for me) Swift 3 app. It will retrieve data from a web server and present it on an iOS device.

I would welcome guidance regarding whether I should use JSON or XML to store the data on the web server? The effort to generate either format will be similar so my real decision driver is on the client side. Volume will typically be 100-250 "records" per request with each record comprising 5-10 text fields.

I don't want to pull in any third-party components but stay entirely Apple.

TIA,

Roy
_______________________________________________
swift-users mailing list
swift-users@swift.org
https://lists.swift.org/mailman/listinfo/swift-users

It's no real help for you, but for me, XML is a document format (store data for a long time), whereas JSON is a transfer format (I really wouldn't prefer JSON over XML for archiving).

But imho JSON won't continue growing in popularity, because finally people seem to rediscover the advantages of binary formats (Protobuf, FlatBuffer… but unless performance isn't critical, I'd probably stick with JSON as well).