1

While sending off Cypher queries to Neo4J's transactional Cypher API, I am running into the following error:

Neo.ClientError.Request.InvalidFormat Unable to deserialize request: Unrecognized character escape ''' (code 39)

My Cypher query looks like this

MATCH (n:Test {id:'test'}) SET n.`label` = 'John Doe\'s house';

While this query works just fine when executed in Neo4J's browser interface it fails when using the REST API. Is this a bug or am I doing something wrong? In case this is not a bug, how do I have to escape ' to get it working in both?

Edit: I found this answer and tested the triple single and triple double quotes but they just caused another Neo.ClientError.Request.InvalidFormat error to be thrown.

Note: I am using Neo4J 2.2.2

Note 2: Just in case it's important, below is the JSON body I am sending to the endpoint.

{"statements":[
  {"statement": "MATCH (n:Test {id:'test'}) SET n.`label` = 'John Doe\'s house';"}
]}
Community
  • 1
  • 1
F Lekschas
  • 12,481
  • 10
  • 60
  • 72

1 Answers1

4

You'll have to escape the \ too:

{"statements":[
  {"statement": "MATCH (n:Test {id:'test'}) SET n.`label` = 'John Doe\\'s house';"}
]}

But if you use parameters (recommended), you can do

{"statements":[
  {"statement": "MATCH (n:Test {id:'test'}) SET n.`label` = {lbl}",
   "parameters" : {"lbl" : "Jane Doe's house"}
  }

]}
Luanne
  • 19,145
  • 1
  • 39
  • 51