The first is invalid json with the last comma inside the last bracket. Take this off:
[ { "data" : "parent", "attr" : { "id" : "root.id" }, "children" : [ { "data" : "child1", "attr" : { "id" : "child1.id" }, "children" : [ ] } ] } ]
Also, starting from version 3.0, or perhaps before you can just insert a new node with json. Recursion is no longer needed.
I created json to create a folder with the name of the income and puts a lot of text files under it, but there may also be folders like parents with a lot of content. See My function below, which inserts this folder into the parent with all the children:
{ "text" : "Income", "id" : "_folder_income", "state" : { "opened" : true }, "children" : [ { "text" : "$125,000 - $150,000", "state" : { "selected" : true }, "icon" : "jstree-file", "id" : "6017897162332" }, { "text" : "$150,000 - $250,000", "state" : { "selected" : false }, "icon" : "jstree-file", "id" : "6017897374132" }, { "text" : "$250,000 - $350,000", "state" : { "selected" : false }, "icon" : "jstree-file", "id" : "6017897397132" }, { "text" : "$350,000 - $500,000", "state" : { "selected" : false }, "icon" : "jstree-file", "id" : "6017897416732" }, { "text" : "Over $500,000", "state" : { "selected" : false }, "icon" : "jstree-file", "id" : "6017897439932" }, { "text" : "$30,000 - $40,000", "state" : { "selected" : false }, "icon" : "jstree-file", "id" : "6018510070532" }, { "text" : "$100,000 - $125,000", "state" : { "selected" : false }, "icon" : "jstree-file", "id" : "6018510083132" }, { "text" : "$40,000 - $50,000", "state" : { "selected" : false }, "icon" : "jstree-file", "id" : "6018510087532" }, { "text" : "$75,000 - $100,000", "state" : { "selected" : false }, "icon" : "jstree-file", "id" : "6018510100332" }, { "text" : "$50,000 - $75,000", "state" : { "selected" : false }, "icon" : "jstree-file", "id" : "6018510122932" } ] }
The same json can also be used to populate the parent folder in the tree:
function insertUrlIntoNode(jsTreeName, url, parentNodeId) { var nodeTree = getSynchronousJson(url); var tree = $('#'+jsTreeName).jstree(true); tree.deselect_all(); var sel = tree.create_node(parentNodeId, nodeTree);