Showing results for 
Search instead for 
Did you mean: 

Load JSON documents with common fields


Hi all

The idea is simple:

Say we have this common document structure:


"company_number": int,

"number_of_employees": int

"company status": string

"date_of_creation": date

"date_of_cessation": date 



But not all companies have a cessation day because they are operative...

Company 1 is still operative:


"company_number": 001,

"number_of_employees": 450

"company status": "OPERATIVE"

"date_of_creation": 01/02/1968

"date_of_cessation": date  (It doesn't have a cessation date)



Company 2 is no longer operative:


"company_number": 002,

"number_of_employees": 500

"company status": "NO OPERATIVE"

"date_of_creation": 01/02/1970




I would like to know If Neo4j allows me to upload these types of JSON documents by using the Cypher query. I don't want that Cypher query fails because date_of_cessation doesn't exist in some documents.

Let me know pls!



There are a few approaches.  Some people like to use the coalesce() function to set a default when the value is missing in the import row.

You could implement some conditional logic leveraging a 'call' subquery. The syntax is like the following. Insert this in your code for each property that you want to conditionally process that may be null. The need for the double 'with' statement is that the query parser will complain that a 'with' in a call subquery has to be simple. To get around this, a second one is added that supports the 'where' clause. 

call {
    with row
    with row
    where is not null
    //do something
    //you can not return a value though

 You could implement conditional logic using apoc methods. Use the do.when() or methods when the query needs to write to the database.

You can use do.when() when the query does not need to write.


Nodes 2022
NODES 2022, Neo4j Online Education Summit

On November 16 and 17 for 24 hours across all timezones, you’ll learn about best practices for beginners and experts alike.