When should we use xml in REST services and when JSON?
What are pros and cons of using json instead of XML?
When should we use xml in REST services and when JSON?
What are pros and cons of using json instead of XML?
This is like asking:
"what are the pros and cons of speaking french vs speaking spanish".
It depends on the context and audience for whatever you are saying.
What are the needs of your service consumers? Are you providing results to other servers or to ajax resquests from browsers? Do you have a simple object, array, or a very complex object with possibly other objects inside the main one? By providing details like that you can list pros and cons. If you can only do one, this question will drive the choice.
I typically allow the client to specify the format they want and return either json or xml. It's just 2 different 'views' or representations of the same resource.
I really cant tell what the pros and the cons are, both of those MIME types require serialization and deserialization of your data. What I can tell is that it's a good habit to offer to client applications the chance to request a specific content type so your service can be consumed by a variety of clients written in different languages.
I would agree with Ray, regarding how you should respond to clients (xml or json). Indeed is a good idea to implement both and give the client the choice to decide the format of the response. Most of the web services i have used support that and is fairly easy to do as you only need to implement two different deserialization/serialization methods for the same object.
I would say that lately more and more WS provide data in json format and it seems to me ore flexible and faster when serializing/deserializing. In addition i find JSON more human-readable especially in complex objects.