apoc.convert.setJsonProperty

Hi,

Note: I don't foresee doing anything with the JSON inserted within Neo4J, it could be considered a very long string, and the semantics are required at the application layer.

I am building a set of API and some of my 'work' so far has been synthetic - especially the JSON I was inserting in a field (body). Anyway, so far I had this:

CREATE (a:Node  { 
    name: 'short name', 
    description: 'long description',
    body: '{it was a simple placeholder JSON body}'
  } ) 
  WITH a MATCH (p:DiffLabel) WHERE elementId(p) = 'a'    
    CREATE (p)-[:hasrel]->(a) 
  WITH a MATCH (t:AnotherLabel {qualifier:'qual'}) 
    CREATE (a)<-[:type]-(t) 
 RETURN elementId(a) as newIdentifier

it was working fine, but now I am inserting actual JSON into the field:

CREATE (a:Node  { 
    name: 'short name', 
    description: 'long description',
  } ) 
  WITH a MATCH (p:DiffLabel) WHERE elementId(p) = 'a'    
    CREATE (p)-[:hasrel]->(a) 
  WITH a MATCH (t:AnotherLabel {qualifier:'qual'}) 
    CREATE (a)<-[:type]-(t) 
  WITH a CALL apoc.convert.setJsonProperty(a, 'body', {REAL JSON})
 RETURN elementId(a) as newIdentifier

The code now creates the node a, but doesn't create the relationships and doesn't return the newIdentifier variable.

I have tried different orders for the apoc procedure (after the create, and now after that matches).

Ideally, I want to keep it all as a single statement (so i don't have to work with transactions)

It worked for me, once I ensured the elementId of 'p' was valid.

BTW- the way I see this procedure working is to take a complex neo4j map and convert it to json format as a string. This means surrounding the keys with escaped double quotes and the whole thing in double quotes (so it is a string).

1 Like