Access JSON Result

Trying to figure out how access neo4j data formatted as JSON (.Net driver). The following cypher returns JSON data. Need to capture and parse this JSON-

MATCH p=(user:User {uid:"uniqueid2" })<-[r*]-(v)
with user, collect(p) as data
CALL apoc.convert.toTree(data, true) YIELD value
return value as user

Trying to access data with-
IResultCursor cursor = await _session.RunAsync(neo4jQuery);

None of my next steps work-
string name = cursor.As();
List people = await cursor.ToListAsync(record => record["name"].As());

Any help would be appreciated.

I can't see how you would get the Json result out from the Neo4j.Driver - it seems to be capturing and converting it to a Dictionary<string, object> - So - I've tried the following code:

var query = @"
    MATCH p=(user:User {uid:'uniqueid2' })<-[r*]-(v)
    WITH user, collect(p) AS data
    CALL apoc.convert.toTree(data, true) YIELD value
    RETURN value AS user";

var cursor = await session.RunAsync(query);
var list = await cursor.ToListAsync(record => record["user"].As<string>());

Which doesn't work, as you get System.Collections.Generic.Dictionary[System.String,System.Object]which is what you get back, so you could do something like this:

var list = await cursor.ToListAsync(record => record["user"].As<Dictionary<string, object>>());

Which would allow you to foreach or linq your way through.

The only way I can find (at the moment) to get a Json response is to use the Neo4jClient instead of Neo4j.Driver - which you would then use like this:

var bgQuery = client.Cypher
    .Match("p=(user:User {uid:'uniqueid2' })<-[r*]-(v)")
    .With("user, collect(p) AS data")
    .Call("apoc.convert.toTree(data, true)")
    .Yield("value")
    .Return (value => value.As<string>());

IEnumerable<string> results = await bgQuery.ResultsAsync;

Which you could then put into a Json parser if you wanted.

Hello Charlotte-
Thank you for the response. Can you point me to a working example of your Neo4jClient method?
When I attempt to implement I get a System.NullReferenceException. I'm clearly missing somethings.

All the best,

Louis

Hi Louis,

This is a fuller version, you will obviously need to get Neo4jClient from Nuget.

var client = new BoltGraphClient("URI", "USER", "PASS");
await client.ConnectAsync();

var bgQuery = client. Cypher
    .Match("p=(user:User {uid:'uniqueid2' })<-[r*]-(v)")
    .With("user, collect(p) AS data")
    .Call("apoc.convert.toTree(data, true)")
    .Yield("value")
    .Return (value => value. As<string>());

IEnumerable<string> results = await bgQuery.ResultsAsync;

All the best

Charlotte