Getting null pointer exception using apoc.import.json

Amit_006_0-1660647654438.png

I have a json file with some data. When I'm trying to import it, I'm getting below exception.

Failed to invoke procedure `apoc.import.json`: Caused by: java.lang.NullPointerException

I exported that file using apoc.export.json.data procedure with jsonFormat:'JSON' format.

file format is something like below.

{
"nodes":
"rels":
}

query:

CALL apoc.import.json("file:///templateData.json")

Data:

{
"nodes": [
{
"type": "node",
"id": "21",
"labels": [
"Resource"
],
"properties": {
"description": "Process bus to interconnect Merging Unit IED, via RNA . It must be connected to a backbone with PTP and RNA functionality",
"neo4jImportId": "1",
"name": "Process bus for Merging Units",
"uuid": "42bec3b7-4789-4ef8-9f73-2968041418cf",
"category": "Bay Level",
"labels": [
"RNA",
"PTP"
]
}
}
],
"rels":
}

Can you post your export query and the exported file, or a portion if big? I don’t see that configuration parameter for apoc.export.json.data.

What does the following you posted represent?

{
"nodes":
"rels":
}

Try exporting without specifying a format. It looks like the import assumes the default format.

@glilienfield Tried with default format. It's working. But what about jsonFormat:'JSON' format.

It seems the apoc.json.import procedure assumes a specific format, which is to have each node and relationship on separate lines. This seems to be the same format the apoc.json.export procedure uses by default ('JSON_LINES'). As such, you can export your data using apoc.json.export and import it with apoc.json.import if you use the default format during export.

The jsonFormat:'JSON' produces a map like structure. Use it if that is what you require.

These references describe it in detail

https://neo4j.com/labs/apoc/4.4/export/json/

https://neo4j.com/labs/apoc/4.4/overview/apoc.import/apoc.import.json/

@glilienfield but in https://neo4j.com/labs/apoc/4.2/overview/apoc.import/apoc.import.json/

clearly mentioned that The apoc.import.json procedure can be used to import JSON files created by the apoc.export.json.* procedures. The above data I have exported through apoc.import.json procedure.

Yes, the link does say that. You will notice the snippet of json they show as an example to import, which was generated by apoc.json,export.all, is in the default format. All the examples use the default format. I believe your problem is solved by exporting your database without specifying the json format, so the data is written in the default format. Afterwards, you should be eagle to import the json file and not get the null pointer exception.