0

I'm new to neo4j.

I consider using it for creating links between multiple entities that I currently store in another DB.

Assuming i have a neo4j graph with multiple labels and multiple relationships.

The graph eventually consists of many subgraphs that are not connected between each other.

I want a json representation of all these subgraphs as an input for later loading to another system.

An example of the graph

In this scenario I don't need to match on a specific label or property. Just need to export the entire graph to an array of subgraphs and have all the properties from each node.

A possible output would be:

{
  "output": [
    {
      "account1": {
        "prop1": "value1"
      },
      "account2": {
        "prop2": "value2"
      },
      "phone1": {
        "prop3": "value3"
      }
    },
    {
      "account3": {
        "propx": "valuex"
      },
      "account4": {
        "prop6": "value5"
      },
      "phone2": {
        "propaa": "valuedd"
      },
      "website1": {
        "prop_web": "value"
      }
    }
  ]
}

Less "cleaner" outputs will also be fine (meaning, if I get "node" objects).

Can this be achieved in neo4j?

Stanislav Kralin
  • 11,070
  • 4
  • 35
  • 58
Lolol
  • 11
  • 1
  • You may find the APOC procedure [apoc.convert.toTree](https://neo4j.com/labs/apoc/4.0/overview/apoc.convert/apoc.convert.toTree/) useful. See [here](https://stackoverflow.com/a/38595482/974731) for an example. – cybersam Sep 09 '20 at 00:21

1 Answers1

0

If you use neo4j browser ("Code" tab), you may spot that browser talking to the database via jsons, i.e. everything that you is able to see in the graph view is serialized to json. In general, neo4j response structured as triple: source node, relationship, and target node. Thus, you'll be able to achieve what you wanted via less "cleaner" output, where each sub-graph will be represented as list of <source node, relationship, target node> triples.