-
Notifications
You must be signed in to change notification settings - Fork 2
/
README.txt
31 lines (20 loc) · 1.1 KB
/
README.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
JSOL stands for JavaScript Object Literal which is a string representing
an object in JavaScript syntax.
For example:
{foo:"bar"} is equivalent to {"foo":"bar"} in JavaScript. Both are valid JSOL.
Note that {"foo":"bar"} is proper JSON[1] therefore you can use one of the many
JSON parsers out there like json2.js[2] or even the native browser's JSON parser,
if available.
However, {foo:"bar"} is NOT proper JSON but valid Javascript syntax for
representing an object with one key, "foo" and its value, "bar".
Using a JSON parser is not an option since this is NOT proper JSON.
You can use JSOL.parse to safely parse any string that reprsents a JavaScript Object Literal.
JSOL.parse will throw an Invalid JSOL exception on function calls, function declarations and variable references.
Examples:
JSOL.parse('{foo:"bar"}'); // valid
JSOL.parse('{evil:(function(){alert("I\'m evil");})()}'); // invalid function calls
JSOL.parse('{fn:function() { }}'); // invalid function declarations
var bar = "bar";
JSOL.parse('{foo:bar}'); // invalid variable references
[1] http://www.json.org
[2] http://www.json.org/json2.js