We Recommend

Pro JavaScript Techniques Pro JavaScript Techniques
Pro JavaScript Techniques is the ultimate JavaScript book for the modern web developer. It provides everything you need to know about modern JavaScript, and shows what JavaScript can do for your web sites. This book doesn't waste any time looking at things you already know, like basic syntax and structures.


Posted By

ecavazos on 01/24/08


Tagged

parse json


Versions (?)


Who likes this?

2 people have marked this snippet as a favorite

adix
rafael


ParseJSON Simplified


Published in: JavaScript 


URL: http://www.json.org/js.html

  1. function parseJSON(json){
  2. try{
  3. if(/^("(\\.|[^"\\\n\r])*?"|[,:{}\[\]0-9.\-+Eaeflnr-u \n\r\t])+?$/.test(json)){
  4. var j = eval('(' + json + ')');
  5. return j;
  6. }
  7. }catch(e){
  8. }
  9. throw new SyntaxError("parseJSON");
  10. }

Report this snippet 

You need to login to post a comment.