apoc.map.flatten

Function

apoc.map.flatten(map MAP<STRING, ANY>, delimiter STRING) - flattens nested items in the given MAP. This function is the reverse of the apoc.map.unflatten function.

Signature

apoc.map.flatten(map :: MAP, delimiter = . :: STRING) :: MAP

Input parameters

Name Type Default

map

MAP

null

delimiter

STRING

.

Usage Examples

The following flattens a nested map using the default . delimiter:

RETURN apoc.map.flatten({
  person: {
    name: "Cristiano Ronaldo",
    club: {
      name: "Juventus",
      founded: 1897
    }
  }
}) AS output;
Table 1. Results
Output
{
  "person.name": "Cristiano Ronaldo",
  "person.club.founded": 1897,
  "person.club.name": "Juventus"
}

The following flattens a nested map using the / delimiter:

RETURN apoc.map.flatten({
  person: {
    name: "Cristiano Ronaldo",
    club: {
      name: "Juventus",
      founded: 1897
    }
  }
}, "/") AS output;
Table 2. Results
Output
{
  "person/club/name": "Juventus",
  "person/club/founded": 1897,
  "person/name": "Cristiano Ronaldo"
}