Welcome, guest | Sign In | My Account | Store | Cart

JSON parser for any object in the script.

OBS: Need a way to identify methods.

JavaScript, 16 lines
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
/**
 * jObject.toJson - JSON Parser
 */
Object.prototype.toJson = function() {
    var tmp = '{';
	/* {"property1":"value1", "property2":"value2"} */    
    for (i in this) {
        if (this[i] != this.toJson) {
            tmp = tmp + '"' + i + '":"' + this[i] + '",';
        }
    }

    tmp = tmp.substring(0, (tmp.length - 1)) + '}';

    return tmp;
}
Created by Danillo Souza on Tue, 27 Jul 2010 (GPL3)
JavaScript recipes (69)
Danillo Souza's recipes (3)

Required Modules

  • (none specified)

Other Information and Tasks