cancel
Showing results for 
Search instead for 
Did you mean: 

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

aditya_digala
Node Link

I am trying to import this JSON file and automatically create nodes out of it but I am getting the following error,

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

My command,
CALL apoc.import.json('https://drive.google.com/uc?id=1MVMAZbrl_nIGruoUsLOkcrw1jcgRli-U')

When locally saved inside import,
CALL apoc.import.json('business_types (1).json')

Refer this file to check indented format of the given file.

JSON Format:

{
    "B2B": [
        {
            "q04ijnd6wjkcgg1cnyq04ijnd0kj42py": [
                "mumbai",
                "lucknow",
                "delhi"
             ]
         }
     ],
    "B2C": [
        {
            "q04ijnd6wjkcgg1cnyq04ijnd0kj42py": [
                "mumbai",
                "lucknow",
                "delhi"
             ]
         }
     ]
}

Output Expected

enter image description here

9 REPLIES 9

dana_canzano
Neo4j
Neo4j

@aditya.digala

couple of issues here

a. what version of Neo4j? / APOC?

b. i downloaded the file you provided and dropped it into a Neo4j 4.3.8 experience and saved the file to import/ and call apoc.load.json("test (2).json"); sucessfully read the file.

c. even through it read the file containing the json it created no nodes/relationships but that is expected. To create said nodes/rels one would typically run

 call apoc.load.json("test (2).json") as value create (n:City {name: value.city});

note this is an example and no necessarily correct given your json. needless call apoc.load.json("test (2).json"); will do nothing more than read the json file.

aditya_digala
Node Link

Hi @dana.canzano,

a. I am using the latest version of Neo4J (4.4)
c. I have clearly used apoc.import.json above hoping it'd load the nodes automatically. (but not apoc.load.json)
Anyway, now that you know the structure of the json file and everything clearly mentioned above, do you have a solution to load the nodes the way I mentioned in my question?

@aditya.digala

The documentation at apoc.import.json - APOC Documentation

indicates

The apoc.import.json procedure can be used to import JSON files created by the apoc.export.json.* procedures.

Was your file created using apoc.export.json?

No it wasn't created using neo4J export json.
Anyway, do you have any alternative to solve this problem?

@aditya.digala

neo4j export json ??? from the browser? or command line ? or ?

alternatives? apoc.load.json

Please solve this problem end to end if you know how to and let me know.
Suggesting only the commands cannot help me as I am a beginner.

@aditya.digala

solving this requires some work on your side. Reading a json file is simply reading a file which has some implied structure, no different than for example reading a CSV file, but the data within the file could be anything. And so its not as if a single command can simply read a file and instant create some model without some understanding of the data there in and its relatioships.

Further from your graphical representation of the data and nodes, are the values in each of the circles the labels for said node or simply a property of a given label. For example the nodes name depicted with 'Chennai', 'Delhi', 'Mumbai', is that 3 different labels or do all 3 nodes have the same label for example, `:City' and each has a respective property named 'name' and with values 'Chennai', 'Delhi', 'Mumbai'.
Further your initial file you are trying to injest is somewhat large. Not that Neo4j can not import it but it might be better to experiment with a smaller file, simply as a means to better understand how to import the data.

Thanks a lot Dana ❤️

@aditya.digala you can look at the video here, that might give you pointers to next steps:

mreca
Node

I was able to load an arbitrary json file with the following steps:

1. Turn on the APOC plugin in your project (which, in the Neo4J UI, contains your databases, the default db of any project being typically "neo4j")

2. Modify your project config file to have this enabled (making it the last line probably works fine)

`apoc.import.file.enabled=true`

3. Copy the JSON file(s) you want to import into the neo4j import/ folder (doable through the Neo4J UI - that link imports a CSV, but you can technically put anything in there, like a JSON file)

4. Then call the load (not import!) function

:param filepath: "relative/path/to/your/file/from/neo4j-import/path";
call apoc.load.json($filepath) yield value
return value

this is the simplest thing you can do with your JSON, just reading it back out through the Neo4J browser. The video linked by @michael_hunger and @aditya_digala above shows more details on how to manipulate your in-memory JSON into on-disk nodes/relationships (it's also the first/only video here).

I know this is over half a year later, but hopefully this helps you and others who need help loading JSON files!

-Mike R