Apoc.convert.fromJsonMap () does not correctly handle escaped characters in strings
Versions: Neo4j 3.2.2 Community; APOC 3.2.0.3
Hidden 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
╒═════════╕
│ "pb" │
╞═════════╡
│ "Foo \ bar" │
└─────────┘
Escaped quotes don't 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 call function apoc.convert.fromJsonMap
: Thrown : java.lang.RuntimeException: Unable to convert {"a": 42, "b": "foo" "," c ": [1,2,3]} on the map with the road
Doubling on the reverse solidus (undesirable) gives the following result:
WITH apoc.convert.fromJsonMap( '{"a":42,"b":"\\"foo\\"","c":[1,2,3]}') AS p RETURN p.b
╒═════════╕
│ "pb" │
╞═════════╡
│ "\" Foo \ "" │
└────────┘
The held newline 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 call function apoc.convert.fromJsonMap
: Thrown : java.lang.RuntimeException: Unable to convert {"a": 42, "b": "foo bar", "c": [1,2,3]} in Map with path
[Note that the newline after "foo" is present in the string returned by the error message. The error message is displayed on two lines.]
Am I using this procedure correctly?
Has anyone seen this issue and fixed or worked around it?
source to share
Using a double backslash instead of a single backslash to start characters actually works.
For example, these 2 queries 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';
source to share