cancel
Showing results for 
Search instead for 
Did you mean: 

Unable to import json file with apoc.import.json

ariel_t
Node

Please keep the following things in mind:

Hi all, I'm trying to rum a GDS algorithm on part of my Neo4j DB. I understand that the best way to do it is to export and import this part to another instance. I have successfully exported it (using apoc.export.json.query), however, I am not able to to import it (using

</>call apoc.import.json("/Users/maish/.Neo4jDesktop/relate-data/dbmss/dbms-f311b29d-500c-428c-87e4-4686e6a2b47d/import/query2.json")</>

as i'm recieving the foloowing error: Failed to invoke procedure apoc.import.json: Caused by: java.lang.NullPointerException.

Looking at the neo4j log, I think it marks an EOF error in line 1, which is rather strange since it was made by the apoc export function. I am able to upload it through apoc.load.json (but the whole purpose was not to bulid the nodes and relationships by myself)

neo4j version is 4.4.3, APOC version is 4.4.0.2

Thanks for the help

9 REPLIES 9

giuseppe_villan
Graph Fellow

@ariel.t

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?

Hello, I am trying the apoc json import, but when I do it it fails with the error and forces me to create a constraint (Failed to invoke procedure apoc.import.json : Caused by: java.lang.RuntimeException: Missing constraint required for import. Execute this query: CREATE CONSTRAINT ON (n:__ENTITY) assert n.neo4jImportId IS UNIQUE;) how to ignore or over come this?

Currently the constraint check is a wanted behavior,
to optimize the import and guarantee the integrity of the result.
If you wanna ignore this check, I would suggest you to open a GitHub issue: Feature request.
This behavior could be configurable, in case.

Thank you, I have a follow up question.
I am getting this exception during apoc json import, how to I enable apoc log in neo4j.config to check this? "ERRORNeo.ClientError.Procedure.ProcedureCallFailed
Failed to invoke procedure apoc.import.json: Caused by: java.lang.NullPointerException"

@krishnan.pb

I don't think you can use the Apoc log procedure to investigate about the causes, in this case.
You should download the project from GitHub, insert into the code some log.info / log.warn etc..., where logs coming from org.neo4j.logging.Log and build your custom jar.


But before doing this, could you provide the `.json` (or a piece of it) which you're trying and the query which fails? And also the apoc version, by executing a `RETURN apoc.version()`.

I using apoc version "4.2.0.10", trying to import json using the procedure "apoc.import.json("file:///all_6_apr.jsonl")" the node that is is failing in import is in the sample below, which was output of apoc.export.json. It's only this node that failed.

{
   "type":"node",
   "id":"8214",
   "labels":[
      "VALUE"
   ],
   "properties":{
      "modificationDate":1648719684687,
      "oid":"96d9452a-0a28-4fe7-9bf8-9dd848164464",
      "creationDate":1648719684687,
      "value":"cases://cases/c3755137-9524-4806-9b8b-0dcf37944560"
   }
}

@krishnan.pb

Mmh nope, I cannot replicate it.
Anyway, I don't know if you changed the export json or just changed it here for readability,
but in general it is better to keep the json without touching it, so with a node for each line,
for example {"type":"node","id":"3","labels":["Product"],"properties":{"productId":1,"neo4jImportId":"3"}}.
If so, I would suggest you open a GitHub issue here and attach your json directly.
Perhaps some chars were lost during the copy and paste here (Afaik you can't attach json, but you could still zip it and attach it).

Thanks @giuseppe.villani Yes, I did the formatting for readability. Initially I did an apoc import from json(which was extracted from apoc json export) and it failed for nodes with this specific label ""labels":["VALUE"]", so I removed these nodes and the dependent relationships and I was able to import the entire json. So it's a bit strange as to why this node with specific labels failed. I will create a json file with just this one node and upload it with all details.

The issue seems to be with this labels

"labels":[
      "VALUE"
   ]

When I change the above to

"labels":[
      "VALUE1"
   ]

the import works... So I am not sure if "VALUE" is some special keyword in APOC import.