I want to response the JSON which likes exported from neo4j browser.
The structure like this.
[
{
"p": {
"start": {
"identity": 2,
"labels": [
"Person"
],
"properties": {
"born": 1964,
"name": "Keanu Reeves"
}
},
"end": {
"identity": 155,
"labels": [
"Movie"
],
"properties": {
"title": "Something's Gotta Give",
"released": 2003
}
},
"segments": [
{
"start": {
"identity": 2,
"labels": [
"Person"
],
"properties": {
"born": 1964,
"name": "Keanu Reeves"
}
},
"relationship": {
"identity": 221,
"start": 2,
"end": 155,
"type": "ACTED_IN",
"properties": {
"roles": [
"Julian Mercer"
]
}
},
"end": {
"identity": 155,
"labels": [
"Movie"
],
"properties": {
"title": "Something's Gotta Give",
"released": 2003
}
}
}
],
"length": 1
}
},
{
"p": {
"start": {
"identity": 2,
"labels": [
"Person"
],
"properties": {
"born": 1964,
"name": "Keanu Reeves"
}
},
"end": {
"identity": 88,
"labels": [
"Movie"
],
"properties": {
"tagline": "Pain heals, Chicks dig scars... Glory lasts forever",
"title": "The Replacements",
"released": 2000
}
},
"segments": [
{
"start": {
"identity": 2,
"labels": [
"Person"
],
"properties": {
"born": 1964,
"name": "Keanu Reeves"
}
},
"relationship": {
"identity": 114,
"start": 2,
"end": 88,
"type": "ACTED_IN",
"properties": {
"roles": [
"Shane Falco"
]
}
},
"end": {
"identity": 88,
"labels": [
"Movie"
],
"properties": {
"tagline": "Pain heals, Chicks dig scars... Glory lasts forever",
"title": "The Replacements",
"released": 2000
}
}
}
],
"length": 1
}
}
]
In order to export json,I use the code like this:
class JsonExtactor(object):
def __init__(self):
super(JsonExtactor,self).__init__()
self.graph = Graph(
"http://localhost:7474",
auth=('neo4j','neo4j'))
def run(self):
try:
return(self.graph.run("MATCH p=()-[r:ACTED_IN]->() RETURN p LIMIT 2", {}).data())
except Exception as e:
print(e)
return None
JsonExtactor().run()
But it only returns a list like this:
[{'p': Path(Node('Person', born=1964, name='Keanu Reeves'), ACTED_IN(Node('Person', born=1964, name='Keanu Reeves'), Node('Movie', released=2003, title="Something's Gotta Give")))}, {'p': Path(Node('Person', born=1964, name='Keanu Reeves'), ACTED_IN(Node('Person', born=1964, name='Keanu Reeves'), Node('Movie', released=2000, tagline='Pain heals, Chicks dig scars... Glory lasts forever', title='The Replacements')))}]
How to response the json format which is like above json structure ?
Please help me
Thanks