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.

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

aqureshi
Node Link

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!

0 REPLIES 0