eval is evil
JSON is a handy, comprehensive format to store/transmit data, especially when working with JavaScript. The syntax looks something like this:
And the good thing in JavaScript is, that all you need to do in order to convert a string into an according object or array, is to call "eval(.)" on that string.
Well, well, this "good" thing is actually a very "bad" thing (especially on the server side, i.e. in helma), since it might encourage programmers to call eval on all kind of unsafe strings. Fortunately there is a free javascript-library available at http://www.crockford.com/JSON/js.html, which parse such strings in a safe way. This library can and should always be used instead of eval!
RubyOnRails (or Ruby in general?) heavily uses YAML as data format, and i must say that i really like that format. But go ahead, and judge for yourself:
-> http://www.yaml.org/start.html
On the website you will also find a Java- as well as a JavaScript-implementation for that format.
var obj = {key1: value1, key2: [value2, value3]}
And the good thing in JavaScript is, that all you need to do in order to convert a string into an according object or array, is to call "eval(.)" on that string.
Well, well, this "good" thing is actually a very "bad" thing (especially on the server side, i.e. in helma), since it might encourage programmers to call eval on all kind of unsafe strings. Fortunately there is a free javascript-library available at http://www.crockford.com/JSON/js.html, which parse such strings in a safe way. This library can and should always be used instead of eval!
RubyOnRails (or Ruby in general?) heavily uses YAML as data format, and i must say that i really like that format. But go ahead, and judge for yourself:
-> http://www.yaml.org/start.html
On the website you will also find a Java- as well as a JavaScript-implementation for that format.
michi - 20.Dec 2005 13:01 - technisches