apoc.map.renameKey

Function APOC Full

Rename the given key(s) in the MAP.

Signature

apoc.metrics.get(map :: MAP?, keyFrom :: STRING?, keyTo :: STRING?, config = {} :: MAP?) :: MAP?

Input parameters

Name Type Default

map

MAP?

null

keyFrom

STRING?

null

keyTo

STRING?

null

config

MAP?

{}

Configuration parameters

Table 1. Config parameters
name type default description

recursive

boolean

true

searches for keys to rename even within submaps or sublists of maps

Usage Examples

apoc.map.renameKey (default config)
WITH {
    old_key: [1, "test", {old_key: "some_value"}],
    otherKey: [1, ["test", {old_key: "some_value"}]],
    name: {old_key: "some_value"},
    other: "key"
 } AS map
RETURN apoc.map.renameKey(map, "old_key", "new_key") as value
Table 2. Results
value
{
  "new_key": [
    1,
    "test",
    {
      "new_key": "some_value"
    }
  ],
  "other": "key",
  "otherKey": [
    1,
    [
      "test",
      {
        "new_key": "some_value"
      }
    ]
  ],
  "name": {
    "new_key": "some_value"
  }
}
apoc.map.renameKey (with config recursive: false)
WITH {
    old_key: [1, "test", {old_key: "some_value"}],
    otherKey: [1, ["test", {old_key: "some_value"}]],
    name: {old_key: "some_value"},
    other: "key"
 } AS map
RETURN apoc.map.renameKey(map, "old_key", "new_key", {recursive: false}) as value
Table 3. Results
value
{
  "new_key": [
    1,
    "test",
    {
      "old_key": "some_value"
    }
  ],
  "other": "key",
  "otherKey": [
    1,
    [
      "test",
      {
        "old_key": "some_value"
      }
    ]
  ],
  "name": {
    "old_key": "some_value"
  }
}