In general, the apoc.import.json
is supposed to be used together with the apoc.export.json.all
, not with the apoc.export.json.query
.
In fact, if I have a database with 3 nodes (:Product) with properties productId and neo4jImportId,
the apoc.export.json.all
produce this file:
{"type":"node","id":"3","labels":["Product"],"properties":{"productId":1,"neo4jImportId":"3"}}
{"type":"node","id":"4","labels":["Product"],"properties":{"productId":100,"neo4jImportId":"4"}}
{"type":"node","id":"5","labels":["Product"],"properties":{"productId":1000,"neo4jImportId":"5"}}
Instead with the call apoc.export.json.query("match (n) return n", file.json)
(note the {"n" ...}
around the node):
{"n":{"type":"node","id":"3","labels":["Product"],"properties":{"productId":1,"neo4jImportId":"3"}}}
{"n":{"type":"node","id":"4","labels":["Product"],"properties":{"productId":100,"neo4jImportId":"4"}}}
{"n":{"type":"node","id":"5","labels":["Product"],"properties":{"productId":1000,"neo4jImportId":"5"}}}
Therefore, if you need to use the apoc.export.json.query
,
you could use the call apoc.load.json("file.json")
procedure, which load without create entites, similarly to LOAD CSV ...
or apoc.load.csv
procedures.
So, if you want to create entities you could execute for example, given a file.json
as above, and using the apoc.create.node procedure:
CALL apoc.load.json("fileQuery.json") yield value
with value.n as n
CALL apoc.create.node(n.labels, n.properties)
yield node RETURN node
In case you still have problems, can you share your .json
exported?