Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 73 lines (45 sloc) 2.101 kb
778200b7 » bjouhier
2012-01-26 first brew
1 ## JASON
2
8a62e409 »
2012-03-06 Update readme.md
3 JASON is just like JSON, but with an A. D'oh. ^U
3b62fbe6 »
2012-03-06 Add closures caveats to the readme
4
778200b7 » bjouhier
2012-01-26 first brew
5 JASON is just like JSON, but unlike JSON it can:
6
7 * serialize objects with methods
8 * serialize objects with cyclic references
9 * understand Dates, Regexps, Booleans, etc, and restore them with `.parse()` with their proper types/classes.
10 * understand and serialize all the JS primitives, including `undefined`
11 * properly recreate the holes in Arrays
12
13 JASON lets you pass objects as text between processes and/or threads.
14
15 Warning: unlike JSON, JASON is *unsafe*. You should only use it in contexts where you have strong guarantees that the strings that you pass to the JASON parser have been produced by a JASON formatter from a trusted source.
16
17 ## Syntax
18
19 JASON syntax is just plain JavaScript (but not JSON).
20
21 The `stringify` function does the clever work of generating whatever Javascript is needed to recreate the object, and the `parse` function is just a call to `eval`.
22
23 ## Examples
24
25 See the `test/test01.js` file.
26
27 ## API
28
29 ``` javascript
30 var JASON = require("JASON");
31
32 str = JASON.stringify(obj);
33 obj = JASON.parse(str);
34 ```
35
36 # Installation
37
38 The easiest way to install `JASON` is with NPM:
39
40 ```sh
41 npm install JASON
42 ```
43
3b62fbe6 »
2012-03-06 Add closures caveats to the readme
44 # Caveats
45
46 JASON won't capture any free vars' values in the serializations. If a JASON serialization contains any functions or methods that contain references to free vars (any other than the built-in globals), most of the times bad things will happen, unless the referenced free vars exist as well and are in scope in the context in which the serialization is JASON.parse()d (the global context), or unless the serialization is eval()ed in a context in which said references exist and are in scope.
47
48 For example here `pi` is a free var:
49
50 ``` javascript
51 var txt= JASON.stringify(function () { return pi });
52 ```
53
54 So this usually won't work:
55
56 ``` javascript
57 JASON.parse(txt)();
58
59 ReferenceError: pi is not defined
60 ```
61
62 unless there's a `pi` var in scope:
63
64 ``` javascript
65 var pi= 3.14;
66 JASON.parse(txt)();
67
68 3.14
69 ```
70
778200b7 » bjouhier
2012-01-26 first brew
71 ## License
72
73 This work is licensed under the [MIT license](http://en.wikipedia.org/wiki/MIT_License).
Something went wrong with that request. Please try again.