apoc.map.get

Function APOC Core

apoc.map.get(map,key,[default],[fail=true]) - returns value for key or throws exception if key doesn’t exist and no default given

Signature

apoc.map.get(map :: MAP?, key :: STRING?, value = null :: ANY?, fail = true :: BOOLEAN?) :: (ANY?)

Input parameters

Name Type Default

map

MAP?

null

key

STRING?

null

value

ANY?

null

fail

BOOLEAN?

true

Usage Examples

The following throws an exception when attempting to look up missing key missingKey with no default value:

WITH {name:"Cristiano Ronaldo",country:"Portugal",dob:date("1985-02-05")} AS map
RETURN apoc.map.get(map, "missingKey") AS output;
Table 1. Results
Output

Neo.ClientError.Procedure.ProcedureCallFailed: Failed to invoke function apoc.map.get: Caused by: java.lang.IllegalArgumentException: Key missingKey is not of one of the existing keys [country, dob, name]

The following returns default value defaultValue when attempting to look up missing key missingKey:

WITH {name:"Cristiano Ronaldo", country:"Portugal", dob:date("1985-02-05")} AS map
RETURN apoc.map.get(map, "missingKey", "defaultValue") AS output;
Table 2. Results
Output

"defaultValue"