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!

Cheers,
-Ryan

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.

Thanks

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

Did you find any solution? For python I read that json serialization blows up because JS can't handle bignums, but not sure about python, I find the serialization can be picky there anyway.
Manually pulling out properties and converting seems like a lot of work...

There seems to be a JSON exporter for neo4j