cancel
Showing results for 
Search instead for 
Did you mean: 

Get Query Results as JSON programmatically

BairDev
Node Clone

I am pretty new to Neo4J and currently using the neo4j-java-driver with bolt for accessing the DB and sending (possible) results back to a frontend. This API will obviously be written in Java and provide REST endpoints with JSON as payload.

Now, should I

  1. somehow transform the query results to JSON (e.g. by using gson) in order to send them
  2. rather use the jdbc-driver
  3. or the REST API of my Neo4J DB?
  4. -- or what else would be the recommended way?

Optional question: I am searching the web for quite some time regarding those questions, but it seems not to be a common task to use the results as JSON. Is this right and if yes, why?

My SO-Question is probably too confused, confusing and naive, but you might find additional information there.

2 REPLIES 2

david_allen
Neo4j
Neo4j

The best way to do this is to serialize a ResultSet object that comes back from a query as JSON.

But there are some kinks to be aware of when you do this.

  • Type compatibility: Neo4j numbers are java Longs, which can represent a wider range of values than JavaScript Number. So be careful when dealing with numeric fields; converting to a Number is too simple and won't always work.
  • Reactive drivers / result size: usually when people want to serialize a resultset as a document, they might not always realize that a document is one big chunk. This is a bad idea if you have a very large number of results.

For this, it doesn't really matter if you use the official Neo4j java client or some other language, the considerations are basically the same.

what's the best way to serialize a ResultSet? from python is this the result.data() to make a dict?