Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the practical difference between xml, json, rss and atom when interfacing with Twitter?

I'm new to web services and as an introduction I'm playing around with the Twitter API using the Twisted framework in python. I've read up on the different formats they offer, but it's still not clear to me which one I should use in my fairly simple project. Specifically the practical difference between using JSON or XML is something I'd like guidance on. All I'm doing is requesting the public timeline and caching it locally.

Thanks.

like image 838
Zenobia Avatar asked Jan 17 '09 11:01

Zenobia


People also ask

What is a difference between XML and JSON?

JSON is a data interchange format and only provides a data encoding specification. XML is a language to specify custom markup languages, and provides a lot more than data interchange. With its strict semantics, XML defined a standard to assert data integrity of XML documents, of any XML sub-language.

Why do we use JSON instead of XML?

JSON is Unlike XML BecauseXML has to be parsed with an XML parser. JSON can be parsed by a standard JavaScript function.


2 Answers

For me it boils down to convenience. Using XML, I have to parse the response in to a DOM (or more usually an ElementTree). Using JSON, one call to simplejson.loads(json_string) and I have a native Python data structure (lists, dictionaries, strings etc) which I can start iterating over and processing. Anything that means writing a few less lines of code is usually a good idea in my opinion.

I often use JSON to move data structures between PHP, Python and JavaScript - again, because it saves me having to figure out an XML serialization and then parse it at the other end.

And like jinzo said, JSON ends up being slightly fewer bytes on the wire.

You might find my blog entry on JSON from a couple of years ago useful: http://simonwillison.net/2006/Dec/20/json/

like image 52
Simon Willison Avatar answered Nov 14 '22 21:11

Simon Willison


RSS and Atom are XML formats.

JSON is a string which can be evaluated as Javascript code.

like image 45
Adrian Heine Avatar answered Nov 14 '22 21:11

Adrian Heine