apoc.map.unflatten

Function APOC Core

apoc.map.unflatten(map, delimiter:'.') yield map - unflat from items separated by delimiter string to nested items (reverse of apoc.map.flatten function)

Signature

apoc.map.unflatten(map :: MAP?, delimiter = . :: STRING?) :: (MAP?)

Input parameters

Name Type Default

map

MAP?

null

delimiter

STRING?

.

Usage Examples

Using the following map and the default . delimiter:

RETURN apoc.map.unflatten({
  `person.name`: "Cristiano Ronaldo",
  `person.club.founded`: 1897,
  `person.club.name`: "Juventus"
}) AS output;

will be returned:

Table 1. Results
Output
{
  "person": {
    "club": {
      "founded": 1897,
      "name": "Juventus"
    },
    "name": "Cristiano Ronaldo"
  }
}

Using the following map and a custom delimiter, that is /é哈:

RETURN apoc.map.unflatten({
  `person/é哈firstName`: "Cristiano",
  `person/é哈lastName`: "Ronaldo",
  `person/é哈club/é哈founded`: 1897,
  `person/é哈club/é哈name`: "Juventus"
}, '/é哈') AS output;

will be returned:

Table 2. Results
Output
{
  "person": {
    "club": {
      "name": "Juventus",
      "founded": 1897
    },
    "firstName": "Cristiano",
    "lastName": "Ronaldo"
  }
}