evalJSON :: String

evalJSON([sanitize]) -> object Evaluates the JSON in the string and returns the resulting object. If the optional sanitize parameter is set to true, the string is checked for possible malicious attempts and eval is not called if one is detected.

If the JSON string is not well formated or if a malicious attempt is detected a SyntaxError is thrown.

person = '{ "name": "Violet", "occupation": "character" }'.evalJSON();

person.name;

//-> "Violet"

person = 'grabUserPassword()'.evalJSON(true);

//-> SyntaxError: Badly formated JSON string: 'grabUserPassword()'

Note

Always set the sanitize parameter to true for data coming from externals sources to prevent XSS attacks.

See also

toJSON

Prototype API 1.5.0 - prototypejs.org