ModelWorks logoModelWorks
JSON TransformString

replaceAll

Replace every occurrence of a substring

replaceAll

Replaces every occurrence of pattern with replacement in a string.

Options

OptionTypeRequiredDefaultDescription
patternstringYesLiteral substring to find.
replacementstringYesSubstring to insert in place of each match.

Example

Input

JSON
"foo bar foo"

Operation

JSON
{ "type": "replaceAll", "options": { "pattern": "foo", "replacement": "qux" } }

Output

JSON
"qux bar qux"

In a Circuit Step

JSON
{
  "name": "scrub_placeholders",
  "description": "Replace every `{{name}}` placeholder with the actual user name",
  "function": "circuit.core.transform.json",
  "input": {
    "source": "${{ input.template }}",
    "operations": [
      {
        "type": "replaceAll",
        "options": {
          "pattern": "{{name}}",
          "replacement": "${{ input.user_name }}"
        }
      }
    ]
  },
  "outputs": [
    {
      "name": "rendered_template",
      "description": "Template with all `{{name}}` placeholders replaced",
      "value": "${{ scrub_placeholders.output.transformed_result }}"
    }
  ]
}

Notes & gotchas

  • Errors with replaceAll: expected string if the input is not a string.
  • pattern is treated as a literal substring, not a regex.
  • An empty pattern will insert replacement between every character — match Rust's String::replace semantics.
  • For first-only replacement, use replace.
On this page

On this page