jmventar
jmventar

Reputation: 697

RESTful API service to send plot data. Which "protocol" use XML or JSON?

I'm developing a platform API with Java and I must choose an exchange data "protocol" to use: JSON or XML.

I've been googling for large coordinates representations Google maps API, MSDN bing services, SVG w3.org coordinate system and also checked some interesting stackOverflow posts: XML vs JSON and Restful API.

All the XML representations I checked used points as a unique element in the xml like this one.

<graph label="first">
  <point x="11-02-2012" y="4573"></point>
  <point x="12-02-2012" y="2341"></point>
<graph>
<graph label="second">
  <point x="11-02-2012" y="3423434"></point>
  <point x="11-02-2012" y="234243"></point>
<graph>

This is a problem for large number of points.

Then I would bet for JSON to manage plot data because I've used it to draw that kind of plots using JQplot plugin and it's more comfortable to use an array of points. But the problem here is that all other components of platform API use XML templates. What would be your choice here?

Upvotes: 0

Views: 561

Answers (2)

QED
QED

Reputation: 9913

JSON is significantly more terse (will use fewer characters to communicate structure), and so it might be a good efficiency choice if you're moving lots of data. It will also be easier to code: most libraries have a function that handles the entire conversion for you.

XML will allow you to add a lot of meta-data and structure around your data. This is a benefit. But it will result in the expected performance hit.

If you anticipate sending only long lists of ordered pairs, I'd say go with JSON. Later on you can always implement an XML presentation if some legacy system demands it.

I don't know much about the other formats you mentioned, so I can't speak to them.

Upvotes: 1

Graham Smith
Graham Smith

Reputation: 25757

Neither are protocols...

XML

XML stands for eXtensible Markup Language.

Ref: http://www.w3schools.com/xml/

JSON

JSON: JavaScript Object Notation.

JSON is syntax for storing and exchanging text information. Much like XML.

JSON is smaller than XML, and faster and easier to parse.

http://www.w3schools.com/json/

So based on the title of your question I would choose neither. However that is me being pedantic.

So it is your platform, and it is good to see you trying to apply standards we know and love. Why not give us a choice by offering both? You are controlling the way the data is sent back so allow the client to specify a preferred language and then if it does not choose one or the other.

The Windows Communication Foundation does this well and makes the developer's life much easier. A good tutorial on this can be found at http://www.codeproject.com/Articles/105273/Create-RESTful-WCF-Service-API-Step-By-Step-Guide where both JSON and XML are offered.

If you aren't using .Net then there are similar setups on different platforms. The bottom line is that once you have gathered your data to return, you should be able to send it to either an XML or JSON output which will then serialize and send it.

If you want an opinion I prefer JSON as it can be easier to transform back into an object on lots of platforms. Also due to its nature it has a smaller footprint. For .Net there is the JSON .Net library and on Java there's Google's GSON, both make life easier for the developer however there are equivalents for XML.

Upvotes: 0

Related Questions