javascript - converting format of JSON -


i using ajax query fuseki, want visualize in d3.js collapsable tree. fuseki returns json in format d3.js code not recognise. this:

{   "head": {     "vars": [ "s" ]   } ,   "results": {     "bindings": [       {          "s": {             "type": "uri",             "value": "http://www.co-ode.org/ontologies/pizza/2005/05/16/pizza.owl#fourcheesestopping"          },          "p": {             "type": "uri",             "value": "http://www.w3.org/2000/01/rdf-schema#subclassof"          },          "o": {             "type": "uri",             "value": "http://www.co-ode.org/ontologies/pizza/2005/05/16/pizza.owl#cheesetopping"          }     ]   } } 

i need convert json format: {

        "name": "pizza",         "children": [             {                 "name": "http://www.co-ode.org/ontologies/pizza/2005/05/16/pizza.owl#pizzabase",                 "children": [                 ]             },             {                "name": "http://www.co-ode.org/ontologies/pizza/2005/05/16/pizza.owl#pizzatopping",                 "children": [                     {                         "name": "http://www.co-ode.org/ontologies/pizza/2005/05/16/pizza.owl#meattopping",                         "children": [                             {                                 "name": "http://www.co-ode.org/ontologies/pizza/2005/05/16/pizza.owl#hotspicedbeeftopping"                             }                         ]                     }                 ]             }         ] } 

i have tried taking json , putting new object correct format, not working. here code:

            var parent = new object();     var childarray=[];     var child =  [];           function createchildobj(_children, children, depth, id, childname, parent, x, x0, y, y0){             var childobj = new object();                 childobj._children = _children;                 childobj.children = children;                 childobj.depth = depth;                 childobj.id =id;                  childobj.name = childname;                 childobj.parent= parent;                 childobj.x = x;                 childobj.x0 = x0;                 childobj.y = y;                 childobj.y0 = y0;                return childobj;              };             console.log(root.length)         (var i=0; i<root.length; i++){             var childname = root[i]["s"]["value"];             var childobj =  createchildobj("children",null, 1, 2, childname, parent, 190, 190, 180, 180);             child.push(childobj);                    }         parent.name = "pizza";         parent.depth = 0;         parent.id = 3;         parent.children= child;         parent.x0 = root.x0;         parent.x = parent.x0;         parent.y0 = root.y0;         parent.y = parent.y0; 

so aiming have parent json object data in correct format parse d3. sorry mess, been fiddling ages trying learn d3, , learning curve steeper had anticipated. great! cheers.


Comments

Popular posts from this blog

javascript - DIV "hiding" when changing dropdown value -

Does Firefox offer AppleScript support to get URL of windows? -

android - How to install packaged app on Firefox for mobile? -