Creating a graph from json using apoc.graph.fromDocument - children's children do not appear in graph

Hi All,

I am trying to create a graph(tree) directly from a json file using following syntax:

call apoc.load.json("file:////file.json") yield value
CALL apoc.graph.fromDocument(value,
{write: false, idField: "uniq_id", labelField: "uniq_id",
mappings: {`$.children`: 'children{!uniq_id}'}})
YIELD graph AS g1 return g1

Each node in the json file has a uniq_id and children list. Each children in the list again have "uniq_id" and their children list. (example below).

Problem
However the problem is that graph is created only for the top root node and its immediate children. Children's children and their children do not come in the graph. I have looked into fromDocument tutorial and this commit but could not figure out how to solve it.

Somehow I have the idea that mappings needs to be modified but don't know how. I am new to neo4j so any help would be highly appreciated.

My json file looks like following:

{
  "uniq_id": "12345",
  "children": [
     {
        "uniq_id":"2345",
        "children": [
           {
              "uniq_id": "Ad345"
              "children": [{...}, {...}]  # nesting can go on
           },
           {
              "uniq_id": "Bd345"
              "children": [{...}, {...}]
           },
        ]
     },
     {
        "uniq_id":"9045",
        "children": [
           {
             "uniq_id": "sd345",
             "children": [
                {"uniq_id": "d23d", "children": [{...}, {...}]},
                {"uniq_id": "d13d", "children": [{...}, {...}]}
             ]
           },
           {"uniq_id": "sd045", "children": [{...}, {..}]}
        ]
     }
  ]
}

Thanks for your time.

What you have is recursive json data. This can be especially tricky to handle properly, but there is a related post which should help:

Explaination

apoc.load.json supports jsonpath, allowing you to restructure the json into something more manageable.

Go to jsonpath.com, and experiment with paths which give you a flat list of all "children". Create a node for every ID, then MERGE your way through as you iterate.