ModelWorks logoModelWorks
JSON TransformString

trim

Remove whitespace from both ends of a string

trim

Removes leading and trailing whitespace from a string.

Options

This operation takes no options; pass an empty object or omit options entirely.

Example

Input

JSON
"   hello world   "

Operation

JSON
{ "type": "trim" }

Output

JSON
"hello world"

In a Circuit Step

JSON
{
  "name": "trim_user_input",
  "description": "Trim leading and trailing whitespace from user input",
  "function": "circuit.core.transform.json",
  "input": {
    "source": "${{ input.raw_query }}",
    "operations": [
      { "type": "trim" }
    ]
  },
  "outputs": [
    {
      "name": "clean_query",
      "description": "User input with surrounding whitespace removed",
      "value": "${{ trim_user_input.output.transformed_result }}"
    }
  ]
}

Notes & gotchas

  • Errors with trim: expected string if the input is not a string.
  • "Whitespace" follows Rust's Unicode-aware definition (spaces, tabs, newlines, non-breaking spaces, etc.). It is not limited to ASCII.
  • Use trimStart or trimEnd to trim only one side.
On this page

On this page