[Solved] Remove quotes from JSON [closed]


Okay, so apparently you want to take out the quotes and indent it nicely? Then I would do that beforehand:

function indent(str) {
    return str.replace(/\n/g, '\n\t');
}

function toPrettyObject(obj) {
    var ajsoln = []; // Actual JavaScript Object Literal Notation

    if(Object.prototype.toString.call(obj) === '[object Array]') {
        for(var i = 0; i < obj.length; i++) {
            ajsoln.push(indent(toPrettyObject(obj[i])));
        }

        return '[\n' + ajsoln.join(',\n') + '\n]';
    } else if(typeof obj !== 'object') {
        return JSON.stringify(obj);
    } else {
        for(var x in obj) {
            ajsoln.push('\t' + (/^[a-zA-Z_\$][\w\$]+$/.test(x) ? x : JSON.stringify(x)) + ': ' + indent(toPrettyObject(obj[x])));
        }

        return '{\n' + ajsoln.join(',\n') + '\n}';
    }
}

8

solved Remove quotes from JSON [closed]