Subj : Re: Serializing JavaScript in spidermonkey To : Marcello Bastea-Forte From : Brendan Eich Date : Wed Dec 31 2003 11:59 am Marcello Bastea-Forte wrote: > I don't need private data or native object support for my project, but I > don't quite understand how JSON applies to what I need other than > showing me what the output should look like. How would I > programmatically generate that code from a JavaScript object in > spidermonkey? That is, is there some built-in method for doing this > already? Yes, see my post at news://news.mozilla.org:119/3FF27935.6090803@meer.net, specifically: ----- See uneval and Object.prototype.toSource (and other .toSource prototype methods for the native classes). eval(uneval(o)) returns an object isomorphic to o, provided the graph rooted at o contains no native functions or other such objects that have no literal form. The uneval global function also works on primitive types, so uneval(true) returns "true", etc. ----- Since you asked about doing this "in spidermonkey", all the support is there. Just uneval the value you want to serialize, to get a string you can store; fetch that string and eval it to deserialize. /be .