cancel
Showing results for 
Search instead for 
Did you mean: 

Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.

Cytoscape JS format JSON

D_C
Node Clone

Hi! I'm trying to render a graph in cytoscape JS which requires a format like this, using python server.

 elements: {
    nodes: [
      {
        data: { id: 'a' }
      },

      {
        data: { id: 'b' }
      }
    ],
    edges: [
      {
        data: { id: 'ab', source: 'a', target: 'b' }
      }
    ]
  },

For a simple graph I can convert it myself by walking through the results

As graphs get more complex, picking out the structures will end up getting convoluted to serialize the data in the right way.

I was thinking this should be a common requirement, maybe someone has a better way?

I was looking at the networkX cytoscape output source code as a reference.

Using subgraphs seems it would make all my queries twice as complex, I hope this isn't needed.

3 REPLIES 3

Can't you just use result.graph() and map the results into nodes and rels to be serialized?

https://neo4j.com/docs/api/python-driver/current/api.html#graph

Could you please elaborate more on your proposition? @michael.hunger
How to serialize this..
Please help.

maheshwar_ligad
Node Clone

@michael.hunger and @gg_lionkhan and @D_C any solution on above issue, Anything work for you. I am looking for similar solution.