How to add/populate properties from a JSON object when creating a node

apoc
neo4j-driver
cypher
javascript

(Aqureshi) #1

EDIT:
Solved it by doing something like

session.run(`CREATE (a:${label} $props)`, {props: properties})

Hi,

I'm trying to create an api that'll let users create nodes and relationships with the properties they define and I am using the javascript neo4j driver.

I was wondering if its possible to do something along the lines of:

var label_var = "some_custom_label";

var properties = {
name: "bob",
age: 25
}
session.run(`CREATE (a:$label ${JSON.stringify(properties)}`, {label: label_var})

and achieve the same result as if I did:

var label_var = "some_custom_label";
session.run('CREATE (a:$label {name: "bob", age: 25})', {label: label_var})

essentially I just want to be able to dynamically add properties to a node i'm creating from a JSON object. Is it possible? Thanks!