ModelWorks logoModelWorks
JSON TransformObject

set

Set a value at a dot-separated path

set

Sets value at a nested location described by path. Intermediate objects are created on the fly when missing.

Options

OptionTypeRequiredDefaultDescription
pathstringYesDot-separated path (e.g., "user.profile.name").
valueanyYesValue to write.

Example

Input

JSON
{ "user": { "id": 1 } }

Operation

JSON
{
  "type": "set",
  "options": {
    "path": "user.profile.name",
    "value": "Ada"
  }
}

Output

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

In a Circuit Step

JSON
{
  "name": "set_user_profile_name",
  "description": "Write a value at user.profile.name, creating intermediate objects",
  "function": "circuit.core.transform.json",
  "input": {
    "source": "${{ record }}",
    "operations": [
      {
        "type": "set",
        "options": {
          "path": "user.profile.name",
          "value": "${{ input.display_name }}"
        }
      }
    ]
  },
  "outputs": [
    {
      "name": "patched_record",
      "description": "Record with display name set on user.profile",
      "value": "${{ set_user_profile_name.output.transformed_result }}"
    }
  ]
}

Notes & gotchas

  • Errors with set: expected object if the input is not an object.
  • Missing intermediate keys are created as empty objects.
  • Existing scalar values along the path are overwritten with objects to make room — set("a.b", 1) on { "a": "string" } will replace "string" with { "b": 1 }. Be careful.
  • path does not support array indices — only object keys. To mutate an array element, use replaceAt or map on the parent.
  • value is not selector-evaluated by set itself; rely on outer selector resolution if the value contains ${{ ... }}.
On this page

On this page