[swift-users] Swift 101: JSON or XML?

Jens Alfke jens at mooseyard.com
Fri Feb 3 13:50:01 CST 2017


> On Feb 3, 2017, at 5:00 AM, Roy Henderson via swift-users <swift-users at 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.

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
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-users/attachments/20170203/61d7828f/attachment.html>


More information about the swift-users mailing list