Is parsing JSON faster than parsing XML

JSON should be faster since it’s JS Object Notation, which means it can be recognized natively by JavaScript. In PHP on the GET side of things, I will often do something like this:

<script type="text/javascript">
    var data = <?php json_encode($data)?>;

For more information on this, see here:

Why is Everyone Choosing JSON Over XML for jQuery?

Also…what “extra effort” do you really have to put into “generating” JSON? Surely you can’t be saying that you’ll be manually building the JSON string? Almost every modern server-side language has libraries that convert native variables into JSON strings. For example, PHP’s core json_encode function converts an associative array like this:

$data = array('test'=>'val', 'foo'=>'bar');


{"test": "val", "foo": "bar"}

Which is simply a JavaScript object (since there are no associative arrays (strictly speaking) in JS).

Leave a Comment