Skip to content Skip to sidebar Skip to footer

Optimized Way To Parse Json Data

I have a JSON data [ { 'Name': 'Tom', 'Email': 'tom@gmail.com', 'Notes': 'Yea, it's good', 'Ratings': '5', 'Messages': [ 'To

Solution 1:

The way you're doing it just now is the most efficient way to do it, except:

varMessages= plainData[j].Messages;
var _messages =" ";
for (var i =0; i <Messages.length; i++)
    _messages +=Messages[i] +"\n";

Could also be written better as :

_messages = plainData[j].Messages.join('\n') + '\n';

Solution 2:

In older browsers (and some not so old) a negative while loop will be faster than a for loop if it can be used:

instead of

for (var j = 0; j < plainData.length; j++) { 

use

var j=plainData.length;
while(j--) {

There used to be a blog with a reference of some quantitative metrics, but that page is dead, however the results could be reproduced fairly easily.

Speculation on why is that the comparison is on equality to zero rather than greater or less than comparisons and also that the Javascript, as an interpreted language could in-line the code to optimize with a known termis point but I don't have quantitative knowlege on this statement.

After a bit of wandering around the web room I found some quantification:

https://blogs.oracle.com/greimer/entry/best_way_to_code_a

Post a Comment for "Optimized Way To Parse Json Data"