score:1

Accepted answer

This will return the value for some instance of the key in the JSON data, if it exists.

var data = {...};
function findValue(json, key) {
  if (key in json) return json[key];
  else {
    var otherValue;
    for (var otherKey in json) {
      if (json[otherKey] && json[otherKey].constructor === Object) {
        otherValue = findValue(json[otherKey], key);
        if (otherValue !== undefined) return otherValue;
      }
    }
  }
}
console.log(findValue(data, 'fileName'));

score:0

It will return a comma separated string of all the values of a specified key

function walk(obj,keyname) {    
    var propertyVal="";                                                                                 
        for (var key in obj) {
            if (obj.hasOwnProperty(key)) {
                var val = obj[key];                                                                                     
                if(typeof(val) == 'object') {
                    console.log(val);                                                                                               
                    propertyVal+= walk(val,keyname);                                                
                }else {
                    if(key == keyname){                                                     
                        propertyVal = propertyVal+","+obj[key];                                                                     
                    }   
                }
            }
        }   
        return propertyVal;                         
}
alert(walk(data,'filename').replace(',',''));

Related Query