Parsing complex JSON results from Neo4j Parsing complex JSON results from Neo4j json json

Parsing complex JSON results from Neo4j


I've written a library specifically for this purpose:

https://www.npmjs.com/package/parse-neo4j

It parses Neo4j's output and extracts only what's been returned in the query, see if it helps!

Neo4j's http endpoint produces result that contains complete query information.

parse-neo4j helps those who only want what they've returned in the query as normal JSON.


I think you're confused by the console.log() output, it's only a short representation, it doesn't always show the entirety of the object (for instance [Object] means there is an inner complex object). results is an object not a JSON string, do a console.log(typeof results); and it will output object.

You can use console.log(JSON.stringify(results, null, 3)); to display the entire object, it will help you to traverse the object by seeing exactly where the properties you need are (it's only for debug sake). Next, you don't need to parse or splice/split anything since result is a valid JS object, stringifiying it only makes things much harder. For example, try console.log(results[0].n[0].properties.lastName);, it should display MacDonald.


After a good night's sleep I thought I would take another crack at this. I progressively walked through the array of objects of arrays of objects etc... and here's what I ended up with - Here is my new else condition...

EDIT: I forgot to mention that I ended up using the lodash library.

} else {    var TechRisk = [];    for ( var i = 0, len = results.length; i < len; ++i) {        TechRisk.push(_.defaults(_.get((_.get(results[i], 'n')[0]), 'properties'),_.get((_.get(results[i], 'n')[1]), 'properties'),_.get((_.get(results[i], 'n')[2]), 'properties'),_.get((_.get(results[i], 'm')[0]), 'properties'),_.get((_.get(results[i], 'm')[1]), 'properties')));    }    res.status(200).send(TechRisk);}

If anyone has a more elegant way to work through my group of nested objects, let me know. This is a bit of brute force and is very brittle (my Cypher query needs to utilize the params so I can pass in different users, etc).

For where I am in the development cycle it gets me moving forward.

Cheers!