aspose file tools*
The moose likes Web Services and the fly likes JSON for data transmit Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Web Services
Bookmark "JSON for data transmit " Watch "JSON for data transmit " New topic
Author

JSON for data transmit

Sunil Gawade
Greenhorn

Joined: Oct 03, 2012
Posts: 28
Can we use JSON for data transmit in Web Services ?
J Dirksen
Author
Greenhorn

Joined: Sep 04, 2012
Posts: 13
Depends what you mean with web service. When using SOAP you're pretty much stuck with XML, when using a REST approach you can define the content-type yourself (most often XML or JSON based).

If you do have to use SOAP you could, in theory, just encode your json and return it wrapped in XML, but I wouldn't recommend that ;-)
Sunil Gawade
Greenhorn

Joined: Oct 03, 2012
Posts: 28
Any size limitation or restriction in JSON ? I mean is it safe to send very large data using JSON considering amount of time to parse data ? or is it better to use XML ?
J Dirksen
Author
Greenhorn

Joined: Sep 04, 2012
Posts: 13
Both XML and JSON are plain text formats. So there won't be much difference in parsing performance I guess.

It really depends on what you call "very large data". Most of the latency will probably be in the network, not the parsing. I've worked with services where the JSON response messages were a couple of MBs, and that doesn't really pose any problems.

And usually JSON/REST doesn't require very large messages. With REST you just use the basic HTTP methods to retrieve resources. So for instance when you're working with large images or video files you normally don't encode these directly into the JSON response. What you do is, you add a link to the image/video in your json response. You client can than retrieve this data by following this link, just like a browser does.

With XML, on the other hand, it's much more common to encode binary files as bas64 and add them to the SOAP Message or use specs like MTOM. This, however, will likely increase the message size significantly and will probably also have an adverse effect on the performance.
Sunil Gawade
Greenhorn

Joined: Oct 03, 2012
Posts: 28
In my scenario "very large data" means set of images and videos. Sending the links of that then actual data make more sense. In this case i can use REST very easily. Thanks for reply...
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: JSON for data transmit