ModelWorks logoModelWorks
JSON TransformObject

renameKey

Rename a single top-level key

renameKey

Renames a top-level key from from to to, preserving the value.

Options

OptionTypeRequiredDefaultDescription
fromstringYesExisting key name.
tostringYesNew key name.

Example

Input

JSON
{ "user_id": 1, "name": "Ada" }

Operation

JSON
{ "type": "renameKey", "options": { "from": "user_id", "to": "id" } }

Output

JSON
{ "name": "Ada", "id": 1 }

In a Circuit Step

JSON
{
  "name": "rename_user_id_field",
  "description": "Rename `user_id` to `id` to match the downstream schema",
  "function": "circuit.core.transform.json",
  "input": {
    "source": "${{ record }}",
    "operations": [
      { "type": "renameKey", "options": { "from": "user_id", "to": "id" } }
    ]
  },
  "outputs": [
    {
      "name": "normalized_record",
      "description": "Record with `user_id` renamed to `id`",
      "value": "${{ rename_user_id_field.output.transformed_result }}"
    }
  ]
}

Notes & gotchas

  • Errors with renameKey: expected object if the input is not an object.
  • If from doesn't exist the operation is a no-op.
  • If to already exists it is overwritten by the value at from.
  • The renamed key moves to the end of the key order (because the implementation removes-then-inserts). To rename in-place at the same position, fall back to entries → map → fromEntries.
  • Only top-level renames are supported. For nested keys, combine unset and set.
On this page

On this page