apoc.map.clean

This function is deprecated. Use Cypher’s map comprehension instead.

Details

Syntax

apoc.map.clean(map, keys, values)

Description

Filters the keys and values contained in the given LIST<ANY> values.

Arguments

Name

Type

Description

map

MAP

The map to clean.

keys

LIST<STRING>

The list of property keys to be removed.

values

LIST<ANY>

The list of values to be removed.

Returns

MAP

Usage examples

The following removes empty string values from a map:

apoc.map.clean
WITH {name: "Cristiano Ronaldo", club: ""} AS map
RETURN apoc.map.clean(map, [], [""]) AS output;
Cypher’s Map Comprehension
WITH {name: "Cristiano Ronaldo", club: ""} AS map
RETURN { k: v IN map WHERE v <> "" | k: v } AS output;
Results
Output
{
  "name": "Cristiano Ronaldo"
}

The following removes empty string values and the keys dob and country from a map:

apoc.map.clean
RETURN apoc.map.clean(
    {name:"Cristiano Ronaldo", country:"Portugal", dob:date("1985-02-05"), club: ""},
    ["dob", "country"],
    [""]
) AS output;
Cypher’s Map Comprehension
WITH {name:"Cristiano Ronaldo", country:"Portugal", dob:date("1985-02-05"), club: ""} AS map,
    ["dob", "country"] AS keys
RETURN { k: v IN map WHERE NOT k IN keys AND k <> "" | k: v } AS output;
Results
Output
{
  "name": "Cristiano Ronaldo"
}