Object type of Node to json

Can you please help me on this?

I have Object type of Node like:

<Node id=1 labels={'First'} properties={'foo': 'foo', 'bar': 'bar'}>

I have tried to use like:

Response(dumps(res), mimetype="application/json")

But it throws an error:

TypeError: Object of type Node is not JSON serializable

1 Like

Hi there!

Which library are you using? If the official Neo4j Driver for Python (Bolt), I think it is correct that Nodes are not JSON serializable. You can retrieve the properties and labels from the Node (https://neo4j.com/docs/api/python-driver/current/types/graph.html) and then build up a standard list/dict and convert that to JSON with json.dumps().

Hope that helps!


Yes, I'm using the official Neo4j Driver for Python. According to you, it's more complicated to grab one by one that is Node.id, Node.labels, etc. Isn't there a way to grab all of them to convert into list/dict?

If not anyways, I'm going to build it manually.


Did you find the solution to this? Can you share your solution?