in xookiEdit.js [99:174]
xooki.json.serialize = function (o, indent) {
// borrowed and adapted from dojo
// summary:
// Create a JSON serialization of the object.
// return:
// a String representing the serialized version of the passed object
if (!indent) {
indent = "";
}
var objtype = typeof(o);
if(objtype == "undefined"){
return "undefined";
}else if((objtype == "number")||(objtype == "boolean")){
return o + "";
}else if(o === null){
return "null";
}
if (objtype == "string") { return xooki.string.escapeString(o); }
if(objtype == "function"){
// do not encode functions
return null;
}
// recurse
var me = arguments.callee;
// short-circuit for objects that support "json" serialization
// if they return "self" then just pass-through...
var newObj;
// array
if(objtype != "function" && typeof(o.length) == "number"){
var res = [];
for(var i = 0; i < o.length; i++){
var val = me(o[i], indent+" ");
if(typeof(val) != "string"){
val = "undefined";
}
res.push(val);
}
return " [\n" + res.join(",\n") + "\n"+indent+"]\n";
}
// generic object code path
res = [];
for (var k in o){
if ("meta" == k) {
continue;
}
// let a chance to the object to define its transient keys, using a meta.isTransient function
if (typeof o.meta != 'undefined'
&& typeof o.meta.isTransient == 'function'
&& o.meta.isTransient(k)) {
continue;
}
var useKey;
if (typeof(k) == "number"){
useKey = '"' + k + '"';
}else if (typeof(k) == "string"){
useKey = xooki.string.escapeString(k);
}else{
// skip non-string or number keys
continue;
}
val = o[k];
// let a chance to the object to define its serialized value
if (typeof o.meta != 'undefined'
&& typeof o.meta.getSerializeValue == 'function') {
val = o.meta.getSerializeValue(o, k);
}
val = me(val, indent+" ");
if(typeof(val) != "string"){
// skip non-serializable values
continue;
}
res.push(indent+" "+useKey + ":" + val);
}
return indent+"{\n" + res.join(",\n") + indent+"}";
};