Skip to content

Rename Keys#

Example to show how to rename Keys in a JSON

Workflow Example

How to use this workflow#

Instructions

  1. Copy the workflow
  2. Navigate to your Workflow editor
  3. Click anywhere in the Workflow² window
  4. Paste the code (ctrl + v or cmd + v)
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
{
  "nodes": [
    {
      "name": "Start",
      "type": "WF²-nodes-base.start",
      "position": [
        640,
        300
      ],
      "parameters": {},
      "typeVersion": 1
    },
    {
      "name": "Rename Keys",
      "type": "WF²-nodes-base.renameKeys",
      "position": [
        1040,
        300
      ],
      "parameters": {
        "keys": {
          "key": [
            {
              "newKey": "NewName",
              "currentKey": "name"
            }
          ]
        }
      },
      "typeVersion": 1
    },
    {
      "name": "Function",
      "type": "WF²-nodes-base.function",
      "position": [
        820,
        300
      ],
      "parameters": {
        "functionCode": "// Don't panic!\n// This is just an Example JSON Data\n\nconst json = `\n  [\n    {\n      \"_id\":\"5078c3a803ff4197dc81fbfb\",\n      \"email\":\"user1@gmail.com\",\n      \"image\":\"some_image_url\",\n      \"name\":\"Name 1\"\n    },\n    {\n      \"_id\":\"5078c3a803ff4197dc81fbfc\",\n      \"email\":\"user2@gmail.com\",\n      \"image\":\"some_image_url\",\n      \"name\":\"Name 2\"\n    }\n  ]\n`;\n\n// Parse the JSON Data and store into a Variable called array\nconst arr = JSON.parse(json);\n\n// Now, Return the Data inside the variable arr\nreturn arr;"
      },
      "typeVersion": 1
    }
  ],
  "connections": {
    "Start": {
      "main": [
        [
          {
            "node": "Function",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Function": {
      "main": [
        [
          {
            "node": "Rename Keys",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}