Which is faster in JavaScript, JSON or SOAP parsing?

Here's the two scenarios.

  1. We are using a manually built xml soap request with xmlhttprequest, sending it to a wcf soap service, getting back the response and using xPath to parse the data and fill out a drop down list.

  2. We are sending a json request to a rest wcf service and getting a json response back and assigning the values to a drop down list

Which scenario is faster? My sense tells me #2 but I could be wrong.

Answers:

Answer

Json will be faster, since Json is essentially Javascript. But that shouldn't be the main motivation. Parsing the data, will assumingly be only a small part of your application anyway.

On the other hand, browsers are also well trained to parse XML.

The main difference is that XML, and therefor SOAP, is larger to send to the client, so the transfer may be a bigger slowdown than the parsing.

Anyway, if you want to know, you should just test and profile instead of guessing or asking.

Answer

Option two would generally be faster than option one, as JSON is a much simpler format than XML.

However, if you really need the parsing to be fast, you shouldn't use either, you should use a custom format that is really fast to parse using simple string operations. For example a comma separated string that could be parsed with a split(',').

Answer

After profiling in my scenario, I found out that JSON is actually much faster as far as processing time within the browser

Tags

Recent Questions

Top Questions

Home Tags Terms of Service Privacy Policy DMCA Contact Us

©2020 All rights reserved.