views:

70

answers:

3

My company is using SOAP for web services. Despite my efforts to convince my peers to use JSON, we still ended up using SOAP. WSDL was one of the main reasons (another is their unfamiliarity with JSON). That kind of annoyed me.

I love JSON for its simplicity and lightweight, but I also like WSDL which provides the description of the data being transmitted. Is there such a description language for JSON? If not, how feasible and practical is it to have one?

+2  A: 

You could come up with a custom description language, but the point of JSON is that it's schema-less.

There is actually something called JSON Schema (Wikipedia page) - have a look at that.

Skilldrick
+1  A: 

Looks like you're looking for JSON Schema or WSDL 2.0? In the latter, you can request JSON by supplying the appropriate Content-Type header in the REST request; the former is more of a "static" description of data (like an XML Schema, say) than the full description of a service (like WSDL) but can be used for the other purpose to some extent.

Alex Martelli
I didn't know WSDL (2.0) can be used to describe anything other than XMl! That's an interesting find. Thanks, Alex!
William
It looks like WSDL 2.0 is, conceptually, the best answer for my question, for being a standard and its wide-spread. Do you know of any implementations/examples out there that uses WDSL2.0 for JSON?
William
@William, actually I know of no implementation of WSDL2.0 -- does the page I pointed to mention any? It _does_ mention that (depending on the content-type header) JSON rather than XML "should" be served, though.
Alex Martelli
No, it doesn't. But I found that article inspiring anyway. :)
William
+2  A: 

When you say JSON, do you mean just the object format or do you mean RESTful services in general? I ask because JSON is really an alternative to XML, and both are ways of serializing data structures and not in themselves web-services.

SOAP's analog is REST (sort of) and you can conceptually use either XML or JSON with both of them, though there's no standard way of saying that you're going to use JSON for serializing a SOAP message as far as I'm aware.

WSDL can map conceptually to WADL for RESTful services, but that's not standardized at all. (I suppose you can use WSDL to describe REST and WADL to describe SOAP, but that'd be hard work; the two specs treat different parts of what is going on as important.)

FWIW, I write services that have both SOAP and REST interfaces, and the REST interfaces support both XML and JSON as data serialization schemes (except for one or two operations where the documents being passed were always in XML already). The key to doing this is to have a principled back-end API that is exposed via SOAP in one natural way and via REST in another; the logical model is identical, but the way you see it is different. This has the advantage of making tooling clients in a wide range of languages trivially possible (which was a strong requirement from the user community); we currently have Java, Ruby and Tcl clients. (The service is in Java with the CXF library, which makes it pretty easy to support both APIs in a single webapp.)

Donal Fellows
+1 for mentioning WADL and for describing a practical approach.
William
Somehow I hope WADL won't become a standard, as there are enough out there. There goes the saying, "A good thing about standards is that there are so many to choose from".
William
@William: You worry too much. A standard is just a description of how to do things that people agree on. (A *de jure* standard is a bit different, with lashings of laws, ISO committees and bureaucracy – the agreement is forced on you – but very little about web services is like that; *de facto* standards are the norm there.)
Donal Fellows
There's also at least one good, practical reason to support both XML and JSON when you can: different client systems have definite preferences. JS prefers JSON, yes, but in others the JSON support is much more primitive relative to the XML support, and there may be other forms that they'd prefer. For example, if you were dealing with a Lisp, Scheme or Clojure shop, you'd have them pressing you to provide S-Expressions as the serialization format. The data structures you're copying about don't care how you serialize them.
Donal Fellows