1 thought on “Deep copmpare of JSON

  1. Meenakshi says:

    Here I am iterating each node and creating meaningful node names. If you notice, instanceOf Array and instanceOf Object pretty much does the same thing

    
    function iterate(obj,parent_node) {
        parent_node = parent_node || '';
        for (var property in obj) {
            if (obj.hasOwnProperty(property)) {
                var node = parent_node + "/" + property;
                if(obj[property] instanceof Array) {
                    //console.log('array: ' + node + ":" + obj[property]);
                    iterate(obj[property],node)
                } else if(obj[property] instanceof Object){
                    //console.log('Object: ' + node + ":" + obj[property]);
                    iterate(obj[property],node)
                }
                else {
                    console.log(node + ":" + obj[property]);
                }
            }
        }
    }

Leave a Reply

Your email address will not be published. Required fields are marked *