Reputation: 31
Versions: Neo4j 3.2.2 Community; APOC 3.2.0.3
Escaped characters in strings are not handled correctly in all instances.
This works as expected:
WITH apoc.convert.fromJsonMap( '{"a":42,"b":"foo\\bar","c":[1,2,3]}') AS p RETURN p.b
╒═════════╕
│"p.b" │
╞═════════╡
│"foo\bar"│
└─────────┘
Escaping quotes does not work as expected:
WITH apoc.convert.fromJsonMap( '{"a":42,"b":"\"foo\"","c":[1,2,3]}')
AS p RETURN p.b
Neo.ClientError.Procedure.ProcedureCallFailed
Failed to invoke function apoc.convert.fromJsonMap
: Caused by: java.lang.RuntimeException: Can't convert {"a":42,"b":""foo"","c":[1,2,3]} to Map with path
Doubling down on the reverse solidus (not desirable) gives this result:
WITH apoc.convert.fromJsonMap( '{"a":42,"b":"\\"foo\\"","c":[1,2,3]}') AS p RETURN p.b
╒═════════╕
│"p.b" │
╞═════════╡
│"\"foo\""│
└─────────┘
An escaped newline character gets the same error:
WITH apoc.convert.fromJsonMap( '{"a":42,"b":"foo\nbar","c":[1,2,3]}') AS p RETURN p.b
Neo.ClientError.Procedure.ProcedureCallFailed
Failed to invoke function apoc.convert.fromJsonMap
: Caused by: java.lang.RuntimeException: Can't convert {"a":42,"b":"foo
bar","c":[1,2,3]} to Map with path
[Note that the newline after "foo" is represented in the string returned by the error message. The error message is given on two lines.]
Is my usage of this procedure correct?
Has anyone seen this problem and fixed or worked around it?
Upvotes: 3
Views: 1327
Reputation: 67019
Using a double-backslash in place of a single backslash to escape characters actually works.
For example, these 2 queries both return true
:
RETURN apoc.convert.fromJsonMap( '{"a":42,"b":"\\"foo\\"","c":[1,2,3]}').b = '"foo"';
RETURN apoc.convert.fromJsonMap( '{"a":42,"b":"foo\\nbar","c":[1,2,3]}').b = 'foo\nbar';
Upvotes: 0