Which is better/faster: json or XML?


I’ve been using XML for quite a while now but I’ve noticed XML gets quite a lot slower when a huge array is included (for example the REST API: users/lookup with 90+ usernames).

Is it wiser to use json instead? If so, why should I do this?
A better question is: Is json really that much faster or did I just experience a small delay with XML?

My final question is about the time between a user update and xml/json file update.
Which one is updated faster, json or XML? With this I mean: when a user posts a new tweet, which file (json or XML) shows the new tweet sooner?

I’ve combined json and XML in my application at this moment but soon I want to change to the best/fastest type.
I’m more familiar with XML because I understand it’s structure better.

Any help is appreciated!



Unfortunately I haven’t received an answer yet so I’m bunping this thread.
Since it’s quite important for me to optimize my application I’d verry much like to know which one is better & faster: json or XML



There shouldn’t be a difference in update speed between the two formats. If a call is slow due to retrieving more data, it will be slow regardless of which payload format is used.

The only major difference in speed would be parsing time, and that’s really dependent on which library and infrastructure you use. My gut feeling is that JSON will be faster to parse, but there are probably more mature XML parsers out there, so it’s likely a toss up. If it really matters that much, I’d suggest writing a few performance tests to determine which works faster in your environment.

Historically, we’ve removed some XML formatted responses in favor of JSON. If you plan on using the Streaming API at any point, I’d suggest making the switch to JSON, since XML is not supported there.


Thanks for the response!

For now I’ll stay with the REST API.
It seems like a wise idea to monitor the time. The size of both content types varies all the time since, for example, users/lookup user_id’s are dynamically added by the script I’ve made.

I’m using simpleXML to load the XML file and break it up into bite sized chunks of data.
Like I’ve already said I’m more familiar with XML due to it’s structure so for now I’ll stay with that type.

When I feel more confident I’ll try experimenting with json and compare the results.
For now, thanks heaps for your reply!


<?php $json = file_get_contents("https://api.twitter.com/1/trends/1.json", true); //getting the file content $decode = json_decode($json, true); //getting the file content as array for ($i=0; $itrends); $i++){ $trend = $decode->trends[$i]; echo " . $trend->name . "; } ?>

which is the error???


It seems like the variable $itrends is not defined.
Perhaps thats your issue.


This tool can help to understand JSON better http://codebeautify.org/view/jsonviewer