JSFiddle - React, Tailwind, and code Playground

by Ben Noble

HTML

<div id='output'></div>

JavaScript

var inJSON = {
  "employee": [{
      "seq": "1",
      "sourceTable": "SOURCE_TABLE1",
      "targetTable": "TARGET_TABLE"
    },
    {
      "seq": "1",
      "sourceTable": "SOURCE_TABLE2",
      "targetTable": "TARGET_TABLE"
    }
  ]
};
inJSON = inJSON.employee;
var outJSON = {
  "nodes": [],
  "links": []
};
var tempNodesArray = [];
var tempNodesJSON = {
  "key": null,
  "color": "orange"
};
var tempLinksArray = [];
var tempLinksJSON = {
  "from": null,
  "to": null
};
for (itms of inJSON) {
  tempLinksJSON["from"] = itms['sourceTable'];
  tempLinksJSON["to"] = itms['targetTable'];
  tempLinksArray.push(tempLinksJSON);
  outJSON.links.push(tempLinksArray);
  if (tempNodesArray.indexOf(tempLinksJSON["from"]) == -1)
    tempNodesArray.push(tempLinksJSON["from"]);
  if (tempNodesArray.indexOf(tempLinksJSON["to"]) == -1)
    tempNodesArray.push(tempLinksJSON["to"])
  tempLinksArray = [];
  tempLinksJSON = {
    "from": null,
    "to": null
  };
}
for (node of tempNodesArray) {

  tempNodesJSON.key = node;
  outJSON.nodes.push(tempNodesJSON);
  tempNodesJSON = {
    "key": null,
    "color": "orange"
  };

}
console.log(outJSON);

var div = document.getElementById('output');

div.innerHTML += JSON.stringify(outJSON);