title: How to Pass JSON object to GOJS javascript file from Java/Prime Faces
body: <p>I have a java class which returns a JSON object and I need to pass this JSON object to gojs javascript, here is the sample of my gojs javascript file(gojs_org_view.js)</p>
  
  <pre><code>function init() {
      var g = go.GraphObject.make;  // for conciseness in defining templates
      myDiagram = new go.Diagram("myDiagram"); // must be the ID or reference to div
      var graygrad = g(go.Brush, go.Brush.Linear, { 0: "rgb(125, 125, 125)", 1: "rgb(86, 86, 86)", 1: "rgb(86, 86, 86)" });
      var unassocArray =[{"id":"12" , "name":"Bugs Bunny", "title":"Head Bunny"}, 
  {"id":"13" , "name":"Honey Bunny", "title":"Wife Bunny"}, 
  {"id":"14" , "name":"Lola Bunny", "title":"Lil' Bunny"}, 
  {"id":"15" , "name":"Mickey Mouse", "title":"Looney In Charge"}];
  </code></pre>
  
  <p>//some javascript code...........</p>
  
  <pre><code>function save() {
      var json = JSON.parse(myDiagram.model.toJson());
    document.getElementById("mySavedModel").value = JSON.stringify(json.nodeDataArray, null, '  ');
    }
    function load() {
      var nodeDataArray = 
  [ {"id":"1", "pid":"1", "name":"Corrado 'Junior' Soprano", "title":"The Boss", "email":"boss@sopranos.net"},
      {"id":"2", "pid":"1", "name":"Tony Soprano", "title":"Underboss", "email":"underboss@sopranos.net"},
      {"id":"3", "pid":"1", "name":"Herman 'Hesh' Rabkin", "title":"Advisor", "email":"hesh@sopranos.net"},
      {"id":"4", "pid":"2", "name":"Paulie Walnuts", "title":"Capo", "email":"paulie@sopranos.net"},
      {"id":"5", "pid":"2", "name":"Ralph Cifaretto", "title":"Capo MIA", "email":"ralph@sopranos.net"},
      {"id":"6", "pid":"2", "name":"Silvio Dante", "title":"Consigliere", "email":"silvio@sopranos.net"}];
      var model = new go.TreeModel();
      model.nodeKeyProperty = "id";
      model.nodeParentKeyProperty = "pid";
      model.nodeDataArray = nodeDataArray;
      myDiagram.model = model;
      myDiagram.undoManager.isEnabled = true;
    }
      function onSelectionChanged(e) {
      var node = e.diagram.selection.first();
      if (node instanceof go.Node) {
        updateProperties(node.data);
      } else {
        updateProperties(null);
      }
    }
  
    // Update the HTML elements for editing the properties of the currently selected node, if any
    function updateProperties(data) {
      if (data === null) {
        jQuery("#selected").css('visibility', 'hidden');
        jQuery("#name").html("");
        jQuery("#title").html("");
        jQuery("#email").html("");
        jQuery("#site").html("");
        jQuery("#superior").html("");
  
      } else {
  
        jQuery("#selected").css('display', 'block');
        jQuery("#name").html("ID: " + data.id  + " Name: " + data.fullname || "");
        jQuery("#title").html("Title: " + data.title || "");
        jQuery("#email").html("Email: " + data.email || "");
        jQuery("#site").html("Site: " + data.siteName || "");
        jQuery("#superior").html("Superior: " + data.pname || "");
      }
    }
  </code></pre>
  
  <p>The javascript variables unassocArray and nodeDataArray are hard-coded instead these values have to come from java class or xhtml(I am not sure which is the best method to send JSON object to gojs javascript file since am new to prime faces and JSON).
  Here is the xhtml code calling gojs</p>
  
  <pre><code>&lt;p:panel id="relationshipsPanel"&gt;
                  &lt;h:outputScript library="js" name="go.js" /&gt;
                  &lt;h:outputScript library="js" name="gojs_org_view.js" /&gt;
                  &lt;h:outputStylesheet library="css" name="gojs_org_view.css"/&gt;
                  &lt;div id="sample"&gt;
                      &lt;div id="myPalette" class="myPaletteClass"&gt;&lt;/div&gt;
                      &lt;div id="myDiagram" class="myDiagramClass"&gt;&lt;/div&gt;
                      &lt;div id="myOverview" class="inner"&gt;&lt;/div&gt;
                      &lt;div id="selected" class="selectedClass"&gt;&lt;/div&gt;
                  &lt;/div&gt; 
              &lt;/p:panel&gt;
  </code></pre>
  
  <p>I tried the hidden value as below, I added following line in my view
  </p>
  
  <p>In gojs_org_view.js i did<br>
      window.console.log("RANA ORG JSON--------------------->"+document.getElementById("relationshipsForm:arrVal").value);
      var nodeDataArray = JSON.parse(document.getElementById("relationshipsForm:arrVal").value);</p>
  
  <p>In the console am getting the following JSON object from view to the javascript but its throwing error "Uncaught SyntaxError: Unexpected token i" at  var nodeDataArray = JSON.parse(document.getElementById("relationshipsForm:arrVal").value);  </p>