JS- how to remove duplicate JSON nodes and add one link for all nodes that get merged JS- how to remove duplicate JSON nodes and add one link for all nodes that get merged json json

JS- how to remove duplicate JSON nodes and add one link for all nodes that get merged


Your question here has little to do with D3: you can manipulate your array with plain JavaScript.

This function looks for the objects on json.nodes based on the property Name. If it doesn't exist, it pushes the object into an array that I named filtered. If it already exists, it increases the value of count in that object:

var filtered = []json.nodes.forEach(function(d) {  if (!this[d.Name]) {    d.count = 0;    this[d.Name] = d;    filtered.push(this[d.Name])  }  this[d.Name].count += 1}, Object.create(null))

Here is the demo: