Evaluating JSON Data

14 Dec

Evaluating JSON data is the most fundamental and common use-case for any modern ajax based web application. The most commonly used method to evaluate json strings has always been eval() but there are few other methodologies that I have learnt recently.

1. eval()

var jsonData = window["eval"](  "("  +  jsonString +  ")"   );

Support:  All Browsers variants

2. new Function()

var jsonData = new Function( " return (  "  +  jsonString +   "  ); " );

Support: All Browsers variants

3. Native JSON Object

var jsonData =  JSON.parse( jsonString );

Support: IE8, FF3

Performance benchmarks for these JSON evaluation methods proves that
Performance of Native   JSON Object > eval() > new Function
PS: new Function > eval() for the gekho browsers

So, we could create a wrapper to make sure JSON data is evaluated efficiently.

function parseJSONData( jsonString ){
         if(JSON !== 'undefined' ){
             return JSON.parse( jsonString );
        }
       if(AjxEnv.isGekho){
            return new Function( "return (  "+jsonString+ " ); " );
       }
       return window['eval'](  "(" + jsonString + ")"  );
};

70 Responses to “Evaluating JSON Data”

  1. Sricharan 02. Jul, 2010 at 5:50 pm #

    Is there any way to compress and pass the json object? Since, I have huge amount of data getting into object it is kicking the performance. If you have any clue plz help me.

Trackbacks and Pingbacks

  1. JOEY - 03. Nov, 2011

    how to buy glucose meter

    Buy_generic meds…

  2. JEREMY - 03. Nov, 2011

    skin cancer foundation australia

    Buy_generic drugs…

  3. CHRIS - 05. Nov, 2011

    clinical features of sickle cell disease

    Buy_generic drugs…

  4. DALE - 05. Nov, 2011

    hot spots or cancer

    Buy_without prescription…

  5. PETER - 06. Nov, 2011

    south beach diet foods to avoid

    Buy_no prescription…

  6. JEFFERY - 06. Nov, 2011

    depression medcine xr

    Buy_drugs without prescription…

  7. CHARLIE - 08. Nov, 2011

    school age adhd self absorbed

    Buy_now it…

  8. BRANDON - 09. Nov, 2011

    altitude and pregnancy

    Buy_it now…

  9. MICHEAL - 09. Nov, 2011

    glucophage powered by vbulletin version 2.2.1

    Buy_generic pills…

  10. DAN - 12. Nov, 2011

    medical nebulizer

    Buy_generic meds…

  11. NATHAN - 12. Nov, 2011

    meal plan for hypertension

    Buy_generic drugs…

  12. RAFAEL - 13. Nov, 2011

    scabies in dogs help

    Buy_generic drugs…

  13. ALFRED - 13. Nov, 2011

    herbals for pregnancy

    Buy_drugs without prescription…

  14. STEVE - 16. Nov, 2011

    drug citalopram side effects

    Buy_generic drugs…

  15. JORGE - 17. Nov, 2011

    air purifiers for allergies

    Buy_generic meds…

  16. WESLEY - 17. Nov, 2011

    diet secrets for models

    Buy_now it…

  17. ALLEN - 10. Dec, 2011

    pietro@atrovent.buy” rel=”nofollow”>…

    Buygeneric meds…

  18. JEREMY - 11. Dec, 2011

    best@medicare.plan.d.for.nexium.40.mg” rel=”nofollow”>..

    Buygeneric meds…

  19. HARRY - 12. Dec, 2011

    infant@prevacid.dose” rel=”nofollow”>.

    Buygeneric drugs…

Leave a Reply