I have a json object which looks like this:
var testJ = {"ROOT":{
        dir : 'app',
        files : [
            'index.html',
            {
                dir : 'php',
                files: [
                    'a.php',
                    {
                        dir : 'extras',
                        files : [
                            'a.js',
                            'b.js'
                        ]
                    }
                ]
            }
        ]
    }};
I need to extract all the files and append into an array (index.html,a.php,a.js..etc)
For this I wrote a javascript code as follows:
var arr=[];
    function scan(obj,append)
    {
        var k;
        if (obj instanceof Object) {
            for (k in obj){
                if (obj.hasOwnProperty(k)){
                    if(k=='files')
                    {
                      scan( obj[k],1 );  
                    }
                }                
        }
    } else {
        body += 'found value : ' + obj + '<br/>';
        if(append == 1)
        arr.push(obj);
        alert("Arr"+ arr);
    };
};
scan(testJ,0);
I am not able to figure out where am I going wrong. Could some give me pointers?
 
     
     
    