Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.
10-23-2021 02:45 PM
Greetings,
I am able to run Call apoc.export.json.query
and have it produce a .json file. However, trying to get my nodejs app to read this Neo4j-generated .json file as it's formatted is not working.
Here's what I'm trying on my server.js file:
const beerNameList = session.run(
CALL apoc.export.json.query(
"Match (b:Beer)
Return b.name as name Limit 5", "../NodeProjects/bnl.json")
)
The resulting bnl.json file looks like this, no commas, no square brackets:
{"name":"Time Twister Imperial Stout"}
{"name":"Viageddon"}
{"name":"Jubelale (2015)"}
{"name":"Distortion"}
{"name":"Orale"}
However, when I try to read this bnl.json file with this Neo4j json formatting, it does not work. Here's what I'm reading with from server.js:
fs.readFile('bnl.json', 'utf8', (err, BNL) => {
if (err) {
console.log(Error reading file from disk: ${err}
);
} else {
const beerNameList2= JSON.parse(BNL);
beerNameList2.forEach(BN => {
console.log(${BN.name}
);
});
}
});
If I manually format my bnl.json file like the following (with commas and square brackets), then my fs.read code works and console.logs the list of beer names:
[{"name":"Time Twister Imperial Stout"},
{"name":"Viageddon"},
{"name":"Jubelale (2015)"},
{"name":"Distortion"},
{"name":"Orale"}]
It seems I need apoc.export.json.query to include [ ] starting and ending square brackets and to comma separate in between each name/curly bracket.
How do I get Neo4j apoc.export.json.query to export with this specific json formatting.
Many Thanks,
keith
All the sessions of the conference are now available online