0

I am going to import some data, and I have the data available in either a JSON feed or a XML feed. I can't decide if I should use the XML or the JSON feed.

What are the pros and cons of choosing either feed, and what is your prefered choice?

Dofs
  • 17,737
  • 28
  • 75
  • 123

4 Answers4

1

XML mean more bytes on the wire: closing tags, by definition, mean XML will be larger than JSON for the same data.

XML tags are human readable meta-data for the data you send. If humans aren't reading it, what does it matter?

XML has XSD schemas for validation.

XML parsers are standard and ubiquitous.

I see both. JSON is starting to be used more and more.

Pick one. It probably doesn't matter much. I'd prefer JSON these days.

duffymo
  • 305,152
  • 44
  • 369
  • 561
0

I would say XML, i just recently discovered a link which you are gonna like it.

http://edwardawebb.com/tips/xml-json

  • "So although the payload is just slightly lighter, it has one major trade-off. XML is a parse-once-and-you’re-done deal. The entire XML file is walked once by Sax, and you just build a neat little Object as you go. With JSON you rely on setting objects to represent the structure of the file and pull pieces using their index. I suspect the JSON parsers walk though the string numerous times. (hence the requirement for a string, and not an input stream like Sax.)" - this statement is ridiculous. It discredits the entire citation, in my opinion. – duffymo Nov 06 '10 at 19:36
0

If you are importing/exporting data, and it needs to be in a reliable format, then I would suggest XML. Yes it is very bloaty, compared to JSON, but you do have the power of XSD Schemas, to make sure the data is in the correct format before you waste time importing it.

However, if you don't have XSD schemas, go with JSON.

Dean Thomas
  • 1,096
  • 1
  • 10
  • 25
0

If you don't want to do any parsing yourself then Json is a nice feature, however you really aren't going to notice much difference no matter which way you go. I've seen plenty of arguments for both sides and I eventually decided that it's really just whatever you want. They are both fairly lightweight and depending on the scenario and data being contained within them both can sometimes perform better or worse than the other. I would say you should do whatever you feel like doing. I like doing Json because in ASP.NET MVC serializing a c# object into JsonResult in my action method is usually quite easy.

CatDadCode
  • 58,507
  • 61
  • 212
  • 318