function json_encode(arr) 
{
    var parts = [];
    var is_list = (Object.prototype.toString.apply(arr) === '[object Array]');

    for(var key in arr)
	{
    	var value = arr[key];
        if(typeof value == "object") { //Custom handling for arrays
            if(is_list) parts.push(array2json(value)); /* :RECURSION: */
            else parts[key] = array2json(value); /* :RECURSION: */
        } else {
            var str = "";
            if(!is_list) str = '"' + key + '":';

            //Custom handling for multiple data types
            if(typeof value == "number") str += value; //Numbers
            else if(value === false) str += 'false'; //The booleans
            else if(value === true) str += 'true';
            else str += '"' + value + '"'; //All other things
            // :TODO: Is there any more datatype we should be in the lookout for? (Functions?)

            parts.push(str);
        }
    }
    var json = parts.join(",");
    
    if(is_list) return '[' + json + ']';//Return numerical JSON
    return '{' + json + '}';//Return associative JSON
}
function json_decode(str_json) 
{   
    // Decodes the JSON representation into a PHP value     
    //    
    // version: 901.2515   
    // discuss at: http://phpjs.org/functions/json_decode   
    // +      original by: Public Domain (http://www.json.org/jsonjs)   
    // + reimplemented by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)   
    // *     example 1: json_decode('[\n    "e",\n    {\n    "pluribus": "unum"\n}\n]');   
    // *     returns 1: ['e', {pluribus: 'unum'}]   
    /*  
        http://www.JSON.org/json2.js  
        2008-11-19  
        Public Domain.  
        NO WARRANTY EXPRESSED OR IMPLIED. USE AT YOUR OWN RISK.  
        See http://www.JSON.org/js.html  
    */  
  
    var cx = /[\u0000\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g;   
    var j;   
    var text = str_json;   
  
    var walk = function(holder, key) {   
        // The walk method is used to recursively walk the resulting structure so   
        // that modifications can be made.   
        var k, v, value = holder[key];   
        if (value && typeof value === 'object') {   
            for (k in value) {   
                if (Object.hasOwnProperty.call(value, k)) {   
                    v = walk(value, k);   
                    if (v !== undefined) {   
                        value[k] = v;   
                    } else {   
                        delete value[k];   
                    }   
                }   
            }   
        }   
        return reviver.call(holder, key, value);   
    }   
  
    // Parsing happens in four stages. In the first stage, we replace certain   
    // Unicode characters with escape sequences. JavaScript handles many characters   
    // incorrectly, either silently deleting them, or treating them as line endings.   
    cx.lastIndex = 0;   
    if (cx.test(text)) {   
        text = text.replace(cx, function (a) {   
            return '\\u' +   
            ('0000' + a.charCodeAt(0).toString(16)).slice(-4);   
        });   
    }   
  
    // In the second stage, we run the text against regular expressions that look   
    // for non-JSON patterns. We are especially concerned with '()' and 'new'   
    // because they can cause invocation, and '=' because it can cause mutation.   
    // But just to be safe, we want to reject all unexpected forms.   
  
    // We split the second stage into 4 regexp operations in order to work around   
    // crippling inefficiencies in IE's and Safari's regexp engines. First we   
    // replace the JSON backslash pairs with '@' (a non-JSON character). Second, we   
    // replace all simple value tokens with ']' characters. Third, we delete all   
    // open brackets that follow a colon or comma or that begin the text. Finally,   
    // we look to see that the remaining characters are only whitespace or ']' or   
    // ',' or ':' or '{' or '}'. If that is so, then the text is safe for eval.   
    if (/^[\],:{}\s]*$/.   
        test(text.replace(/\\(?:["\\\/bfnrt]|u[0-9a-fA-F]{4})/g, '@').   
            replace(/"[^"\\\n\r]*"|true|false|null|-?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?/g, ']').   
            replace(/(?:^|:|,)(?:\s*\[)+/g, ''))) {   
  
        // In the third stage we use the eval function to compile the text into a   
        // JavaScript structure. The '{' operator is subject to a syntactic ambiguity   
        // in JavaScript: it can begin a block or an object literal. We wrap the text   
        // in parens to eliminate the ambiguity.   
  
        j = eval('(' + text + ')');   
  
        // In the optional fourth stage, we recursively walk the new structure, passing   
        // each name/value pair to a reviver function for possible transformation.   
  
        return typeof reviver === 'function' ?   
        walk({   
            '': j   
        }, '') : j;   
    }   
  
    // If the text is not JSON parseable, then a SyntaxError is thrown.   
    throw new SyntaxError('json_decode');   
}  

