Neo4J CYPHER in C# or Java: Return JSON output from “call db.schema.nodeTypeProperties()”?

When calling db.schema.nodeTypeProperties() from within the Neo4J Broswer, the Code side tab returns the complete JSON schema in the Response drop-down. Is it possible to retrieve this JSON result in C# or Java using the Neo4J.Driver? I would like to deserialize the JSON text into C# classes.

Screen-cap of Response drop-down from db.schema.nodeTypeProperties()

I have explored the Neo4J.Driver IDriver , IAsyncSession and IResultCursor calls and cannot find a way to retrieve the JSON dataset.

Any suggestions?

James Mireles
Houston, TX

with a query like this:

call db.schema.nodeTypeProperties() yield nodeType,nodeLabels,propertyName,propertyTypes,mandatory 
return collect( {type:nodeType,labels:nodeLabels,name:propertyName,type:propertyTypes,m:mandatory})```

you can transform the data to an object in the shape you want and return it to the driver as JSON.
1 Like

Another option you have is to use the REST endpoint, something like:

var client = new RestClient("http://localhost:7474");
client.Authenticator = new HttpBasicAuthenticator("neo4j", "neo");

var query = "{\"statements\" : [ { \"statement\":\"call db.schema.nodeTypeProperties()\", \"parameters\" : {} }] }";

var request = new RestRequest("db/neo4j/tx/commit",DataFormat.Json);

var content = client.Post(request).Content;

That should be in JSON (I'm using RestSharp in the code).

1 Like

@webtic, @charlotte.skardon, thank you both for your suggestions. I experimented with them and other approaches and was able to get what I wanted by using apoc.export.json.all to stream in a JSON dataset of the entire database. I leveraged the examples at I apologize for what turned out to be the misdirection of my question. db.schema.nodeTypeProperties() was not going to get me what I really needed.

using Newtonsoft.Json.Linq;

public async void TestNeo4j()
    // Set up the graph database driver and connect the session to the Neo4J database.
    IDriver driver = GraphDatabase.Driver(Neo4JBoltURI, AuthTokens.Basic(Neo4JUser, Neo4JPassword));
    IAsyncSession session = driver.AsyncSession();
    IResultCursor cursor;

        // Bring the JSON text in as a stream
        string query = "CALL apoc.export.json.all(null,{stream:true,useTypes:true}) " +
            "YIELD file, nodes, relationships, properties, data " +
            "RETURN file, nodes, relationships, properties, data";

        cursor = await session.RunAsync(query);
        string sJsonData = await cursor.SingleAsync(record => record["data"].As<string>());

        //// Save the JSON to a file.
        //string path = @"C:\Users\Public\Documents\Neo4JExportAll.json";
        //if (File.Exists(path)) File.Delete(path);
        //File.WriteAllText(path, sJsonData);

        // Each line is a separate JSON statement describing a node or a relationship
        // Iterate all statements
        using (StringReader reader = new StringReader(sJsonData))
            string line = string.Empty;
                line = reader.ReadLine();
                if (line != null)
                    // Deserialize the JSON line into JObject jo.
                    JObject jo = JObject.Parse(line);
                    // Dig into the JObject to get the data from the stream.

            } while (line != null);
        await session.CloseAsync();

1 Like

Thanks the feedback and posting your solution!