apoc.map.get

Details

Syntax

apoc.map.get(map, key [, value, fail ])

Description

Returns a value for the given key. If the given key does not exist, or lacks a default value, this function will throw an exception.

Arguments

Name

Type

Description

map

MAP

The map to extract a value from.

key

STRING

The key to extract.

value

ANY

The default value of the given key. The default is: null.

fail

BOOLEAN

If a key is not present and no default is provided, it will either throw an exception if true, or return a null value The default is: true.

Returns

ANY

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;
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;
Results
Output

"defaultValue"