I am using the bolt driver(1.0.1) with python. How can I convert the result into a Json so that I can return it to through a flask app? That is I need to convert datatype, "neo4j.v1.types.Record" to "json".
I tried this
from flask import Flask
from neo4j.v1 import GraphDatabase, basic_auth
import json
driver = GraphDatabase.driver("bolt://localhost:7687", auth=basic_auth("neo4j","neo4j"))
session = driver.session()
app = Flask(__name__)
@app.route('/hello/<prop>')
def hello_name(prop):
result = session.run("MATCH ...") #this works perfectly fine and the data is captured in result
session.close()
for record in result:
return json.loads(record)
This throws an error :- TypeError: the JSON object must be str, not 'Record'
The neo4j driver gives the result in a generator.(Record Type) You cannot do json.load as it is not a json serialized string.
What you can do :
for record in result:
print result[0]
See the format of the result and take the elements you like.
For further understanding on how to parse neo4j records: http://neo4j.com/docs/api/python-driver/current/session.html
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With