Section 7.2. Should you use XML or JSON?


7.2. Should you use XML or JSON?

Joe and the JavaScript guys want to look at JSON, but Frank's PHP team thinks XML is the way to go. Which is the best data format? In this chapter, we're going to let JSON and XML take each other on, and see which one survives the ULTIMATE DATA FORMAT CHAMPIONSHIP.

XML, the heavyweight champion of data formats.

JSON is a relative newcomer, and is poised to give XML a run for his title as reigning data format champion.

Fighting Words

Today's adrenaline-laced, psyched-up fighters:

XML and JSON

XML: (glares at JSON)

JSON: Your time has finally come, XML. Tonight, the world is gonna see that you've lost a step, especially when it comes to JavaScript and asynchronous applications.

XML: I've heard that one before... but here I am, still the reigning data format in the world.

JSON: You're only at the top because people think that there's nothing else available. I know lots of people that can't stand you, XML... you're big and bloated, and a real pain to work with.

XML: I'm big because I can handle anything. Snowboard sales, HTML, purchase orders... you throw it at me, I'll take care of it. No problem. You think a little pipsqueak can handle all those different types of data? I don't think so.

JSON: Maybe not, but I'm fast... a lot faster than you, most of the time.

XML: I'm plenty fast, especially if you use my attributes. And, I'm versatile... I can do all sorts of things, like represent a math equation or a book.

JSON: Yeah, well, most of my users aren't too interested in sending math equations across the network. Besides, all those angle brackets? Ugh... anyone that knows arrays can start working with me without having to learn all that weird XML syntax.

XML: But can someone transform you into something else? Like with XSLT? Or what about web services... you gonna tell me you can handle web services?

JSON: Wow, you've really been a bit overused, haven't you... you're missing the point, brackethead I don't care about all those things. I just care about getting information from a web page to a server and then back without a bunch of extra work... like having to crawl up and down a DOM tree. Know anyone who thinks that's fun?

XML: Uh, yeah. Hello? We've got a whole group of DOM experts out there these days, writing killer user interfaces. Did you see that Top 5 CDs listing? That was pretty cool, and it was only about 100 lines of code. Anyone that knows the DOM is ready to use XML, today!

JSON: Look, all developers really need is a lightweight data format that's easy to work with in JavaScript. And that's me, big boy, not you.

XML: What are all the servers going to think about this? You know, PHP and Perl and Java... I don't see them lining up to throw their support in with you and your "lightweight data format" spiel.

JSON: Well, I guess that's true... but there are libraries that those guys can use to work with me.

XML: Libraries? If they've got to use a library, why not use a standard like the Document Object Model?

JSON: My libraries might be standard one day, too, you know....

XML: But here I am, being used right now, because I'm already a standard. At the end of the day, you're just one more proprietary data format. Maybe you've got a few more fans than comma-separated values, but I'll put an end to that.

JSON: Oh really? Let's get it on, XML.





Head Rush Ajax
Head Rush Ajax (Head First)
ISBN: 0596102259
EAN: 2147483647
Year: 2004
Pages: 241

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net