cancel
Showing results for 
Search instead for 
Did you mean: 

Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.

Neo4j Export JSON Format

keithave
Node Clone

Greetings,

  • Neo4j 3.5.6 Community
  • nodejs driver 4.3.0
  • plugin: apoc-3.5.0.3-all
  • node.js

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

0 REPLIES 0