5 ms·
Twitter Goes JSON-Only With One API
- cloudwalking 16y agoOther than smaller bandwidth on each call, what advantages does JSON provide over XML?
- kennu 16y agoDirect mapping to most (dynamic) programming languages' datatypes, such as arrays, dictionaries, numbers and strings. Once you get used to working with a combination like JSON and Python, you really don't want to go back to the complexity and inconvenience of parsing and generating XML.
- d0m 16y agoBut still, deprecating XML means lots of already functional apps won't work anymore. Maybe a "All new app registered after X date will only be able to use JSON formatted data" would be better.
- simonw 16y agoThey're not ditching XML for their regular APIs, just for the streaming API - which has been in beta for just a few months, and probably doesn't have that many XML clients (I imagine Twitter looked at the number of requests the XML endpoint was getting before deciding to deprecate it).
- zdw 16y agoBenefits JSON > XML: Less bandwidth for same data, Quick to load, quick to parse. Very web friendly. Benefits of XML > JSON: Easy to validate structure and content (via schemas), and transform content in a language neutral manner (via xslt). Older, thus supported in more places. Use what works - JSON is fine for web stuff, XML is better for things that need strict validation and/or long term data storage.
- deleted 16y ago[deleted]
- andrewvc 16y agoI never really got the 'why' behind XML Schemas. Why would you validate a document with a schema vs actual code? It's just a bigger pain in the ass, and more limited.
- RodgerTheGreat 16y agoIf you have multiple applications using a document format, XML schemas are a good way to make sure they all agree on the semantics of the format. Recall that XML was originally intended as a means of bridging different environments and platforms, where code will not necessarily be portable.
- andrewvc 16y agoI guess, but even if that's the case, who cares if the message is formatted right if it's still invalid. I guess I haven't really worked in a heterogenous environment with a lot of XML before though, I can see the potential value there, but i'm still doubtful.
- zdw 16y agoThe big win for schemas is being able to use them to make assumptions about input, which simplifies your code. For example, if you have an RelaxNG schema (which has a great compact syntax) that says that an element has to have at least one child node and that child node contains an integer between a certain set of values. Once you have that schema, you could write code that could read in the XML file and validate it against the schema in 2 lines, then grab all the child node integers with one XPath expression. The data might be junk (heck, I'm not aware of any format that is impervious to worthless data), but at least it's junk in the right format, and you never had to mess around with parsing the input. Need to switch programming environments or languages because you're working on Unix/Windows/embedded system/mainframe/database/web browser ? The schema can move with you (or be converted to another schema format that does), and programming niceties SAX and XPath will often carry over too.
- simonw 16y agoHere's a piece I wrote about JSON v.s. XML back in 2006: http://simonwillison.net/2006/Dec/20/json/ http://simonwillison.net/2006/Dec/20/json/
- RodgerTheGreat 16y agoXML is actually very hairy and complicated. Consider entity encoding, whitespace (as in xml:space="preserve"), and namespaces. In contrast, the complete syntax of JSON is given in 5 simple flowcharts: http://json.org/ http://json.org/ Nearly any competent programmer could hand-roll a tested, production-ready JSON parser in under a week. Try doing the same with XML. In practice there are plenty of JSON parsers out there to choose from, but being able to completely wrap your head around something is useful.
- dkarl 16y agoI upvoted your comment for the info, but I have no idea why this is an advantage for anyone except the handful of people who create an implementation. Hand-rolling an XML parser is a pretty sure sign of a certain kind of incompetence. Wouldn't the same be true of hand-rolling a JSON parser, unless you're one of the (rare) first guys to solve the problem for your language or language platform? To put it another way, wouldn't this only have been an advantage before XML libraries became commonplace? The last time I reached for an XML library and found there was none already installed with my platform, I was using Tcl (and it wasn't hard to find TclXML.)
- asnyder 16y agoYou'll likely still be able to get results in XML via YQL which offers their own XML or JSON outputs for most web services.
- simonw 16y agoYQL won't work for Twitter's streaming API - it's designed for standard request/response style APIs.
- bluedevil2k 16y agoHooray! Let's hope other websites follow their lead and ditch the huge SOAP/XML overhead and stick with the ease and simplicity of REST/JSON.
- buro9 16y agoAt Yell we're currently working on our first public API, and only on Friday did we have the conversation and decided that doing JSON well was far more important than supporting XML at all. The decision was a quick one, we just asked the iPhone, Android and web devs where we should focus, what they wanted most. The answer was unanimously JSON.
- guelo 16y agoTwitter's XML API does not use SOAP.
- jtchang 16y agoThank god. I hate XML. XML has its uses but honestly when it comes down to it working with JSON is a lot easier. When picking a data interchange format you need to consider indirect advantages as well. JSON is easier to read on a screen, type out, and overall skim. Skimming XML is a pain.
- thibaut_barrere 16y agoThe only thing I miss from XML is the ability to comment out something. I discovered the other day that it wasn't apparently possible.
- davepeck 16y agoFormats targeted strictly at machine/machine interchange ultimately get used for much more. JSON is no exception. Configuration tends to be the first place that interchange formats are "abused"; even for such a mild abuse, comments are essential. (Hard-core abuses, like XML-based programming languages, are another thing entirely. :-) To deal with JSON's lack of comments, I've considered writing services and apps that produce JSON, but consume YAML. Here, the interesting qualities of YAML are (1) it's a superset of JSON, and (2) it supports comments.
- KaeseEs 16y agoYAML isn't a strict superset of JSON, although since YAML 1.2 it is very nearly so; with just a little bit of care you can avoid the edge cases (eg. you can have hash keys longer than 1024 characters in JSON but not in YAML), provided you are cognizant of them.
- deleted 16y ago[deleted]
- viraptor 16y agoI'm quite surprised. What did you need the comments for?
- runT1ME 16y agoSigh I just implemented my project's API in XML. Time to switch I guess...
- polynomial 16y agoSince the 1st line of the article indicates this is the streaming API only, I will presume that's the one your project is written against.
- Jach 16y agoOn XML vs. JSON, I used to hate XML until I started programming in ActionScript which has a really nice syntax for it (except a few oddities here and there). I use Enunciate at work ( http://enunciate.codehaus.org/ http://enunciate.codehaus.org/ ) which generates XML, JSON, AMF, SOAP/REST endpoints all by itself from base Java services and classes, which works well too. Can't say I'm disappointed, back when I did twitter dev I used JSON for everything, plus it was really easy to interface with our JavaScript client (duh).
- tomjen3 16y agoI haven't used Action script but Scala has really nice support for Xml - it is properly the only language that allows you to do pattern matching on XML.
- simonw 16y agoScala's creator is on record as regretting the inclusion of XML literals in the syntax of the language: http://www.codecommit.com/blog/scala/working-with-scalas-xml-support http://www.codecommit.com/blog/scala/working-with-scalas-xml...
- jhrobert 16y agoImpedance mismatch between XML and JavaScript is killing XML. What's next? HTML? {"head":{"title": "JOHN"},"body:"{"div": "Javascript Object Hypertext Notation"}}
- jluxenberg 16y agoThe article on Programmable Web doesn't add any value to the original press release: http://groups.google.com/group/twitter-development-talk/browse_thread/thread/6959dc497e4dc546/d8f58c013dc29f4e http://groups.google.com/group/twitter-development-talk/brow...