News for hackers. Stuff that matters.
Re:BART - The Real BART API (beta) by csytan on Tuesday January 26, 2010 @04:31AM (#1077418)
I'm always surprised when new APIs are released using XML. JSON is easier to produce and consume, so why's it taking so long to become standard?
Re:BART - The Real BART API (beta) by thibaut_barrere on Tuesday January 26, 2010 @05:29AM (#1077457)
A large part of the developers I know (ie met physically) are not even aware of what JSON is (although it definitely contrasts with the web/ruby/python/javascript world).

Another point is that API to parse XML are built-in (and widely known) in almost all platforms, whereas JSON requires external libraries on some (I believe .Net, Java for instance).

Re:BART - The Real BART API (beta) by pvg on Tuesday January 26, 2010 @05:37AM (#1077464)
I think that's exactly it - XML integration, serialization to XML tends to be built-in to many existing environments. If the BART site is any clue, they are using ASPX/.NET.

The XML they are using is also very straightforward, elements-only, no attributes, namespaces, SOAP, other weirdness. It doesn't look any harder or easier to produce and consume than JSON. For part of their previous offering they are using a Google-designed format called GTFS which seems to be essentially well-defined CSV.

Re:BART - The Real BART API (beta) by IgorPartola on Tuesday January 26, 2010 @08:57AM (#1077713)
Encoding JSON is very easy. If that's all you are doing (e.g. only sending data to the client through say a web API), and you don't have a native library: build one.

Edit: also, I am a big fan of providing both. It can be done simply and cleanly, so why not.

Re:BART - The Real BART API (beta) by ionfish on Tuesday January 26, 2010 @04:35AM (#1077428)
Because XML is enterprise.
Re:BART - The Real BART API (beta) by Confusion on Tuesday January 26, 2010 @06:52AM (#1077529)
Namespaces are a good idea. Having both attributes and child elements is a good idea. The combination of those two allows for easy, partial, versioning of your schema. The ability to impose an ordering is also a nice idea.

http://confusion.tweakblogs.net/blog/816/json-to-xml-convers...

Re:BART - The Real BART API (beta) by csytan on Tuesday January 26, 2010 @09:50AM (#1077776)
I'm not convinced. JSON objects have attributes and can contain child elements. Ordering can be provided by arrays.

Namespaces are also easy to create within objects; an example would be the "type" attribute from the Freebase API.

For versioning, many APIs are accessed through a different subdomain or URL (e.g. http://api.example.com/v2/). If you're feeling somewhat enterprisey, you can also wrap your response in an "envelope" object containing all the necessary details to implement your own custom protocol.

Re:BART - The Real BART API (beta) by Confusion on Tuesday January 26, 2010 @12:12PM (#1078159)

  JSON objects have attributes and can contain child elements
JSON objects only have members. These are indistinguishable from each other and there isn't a separate species of them that is obviously metadata for the object itself. Of course you can use some special naming scheme to indicate those, but if everyone whips up their own naming scheme, consuming JSON from multiple sources becomes a maintenance nightmare, especially in the absence of something like an XSD.

  Namespaces are also easy to create within objects;
The same arguments holds here: if everyone whips up their own version of namespacing, by using some special member to indicate the namespace, interpreting JSON from different sources becomes that much more of a maintenance hell. Moreover, many users will not use namespaces, as it isn't required. XML forces you to think about the structure of your data representation.

  For versioning, many APIs are accessed through a different subdomain or URL
The physical URL through which an API is accessed should be entirely different from the virtual URI's used for namespaces and versioning.

Now I fully agree that XML and the various specs surrounding it are bloated and overengineered, but there are some sound ideas in there that a replacement should attempt to keep. JSON can be used for simple cases, but as soon as the problem gets slightly more complex, you start adding non-standardized extensions to JSON, to obtain goals that XML has foreseen. I don't believe they can replace each other: they both have their own niche.