apoc.map.flatten

Details

Syntax

apoc.map.flatten(map [, delimiter ])

Description

Flattens nested items in the given MAP. This function is the reverse of the apoc.map.unflatten function.

Arguments

Name

Type

Description

map

MAP

A nested map to flatten.

delimiter

STRING

The delimiter used to separate the levels of the flattened map. The default is: ..

Returns

MAP

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;
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;
Results
Output
{
  "person/club/name": "Juventus",
  "person/club/founded": 1897,
  "person/name": "Cristiano Ronaldo"
}