Friday, May 10, 2024
 Popular · Latest · Hot · Upcoming
151
rated 0 times [  154] [ 3]  / answers: 1 / hits: 18757  / 16 Years ago, sat, march 14, 2009, 12:00:00

An ajax request returns me a standard JSON array filled with my user's inputs. The input has been sanitized, and using the eval() function, I can easily create my javascript object and update my page...



So here's the problem. No matter how hard I try to sanitize the inputs, I'd rather not use the eval() function. I've checked google for ways to use JSON in AJAX without eval and have ran accross a bunch of different methods...



Which one should I use? Is there a standard, proven-secure way of doing this?


More From » ajax

 Answers
2

json.org has a nice javascript library



simple usage:



JSON.parse('[{some:json}]');
JSON.stringify([{some:'json'}]);


Edit: As pointed out in comments, this uses eval if you look through its source (although it looks to be sanitized first)



to avoid it completely, look at json_parse or json-sans-eval



json2.js is insecure, json_parse.js is slow, json-sans-eval.js is non-validating


[#99846] Monday, March 9, 2009, 16 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
marint

Total Points: 550
Total Questions: 105
Total Answers: 124

Location: Zambia
Member since Sat, Oct 31, 2020
4 Years ago
marint questions
;