ModelWorks logoModelWorks
JSON TransformString

substring

Extract a substring by byte index

substring

Returns the slice of a string between start (inclusive) and end (exclusive). Both indices are clamped to the string length, so out-of-range values are safe.

Options

OptionTypeRequiredDefaultDescription
startintegerYesInclusive start index, in bytes.
endintegerNostring lengthExclusive end index, in bytes.

Example

Input

JSON
"hello world"

Operation

JSON
{ "type": "substring", "options": { "start": 6, "end": 11 } }

Output

JSON
"world"

In a Circuit Step

JSON
{
  "name": "extract_short_id",
  "description": "Take the first 8 characters of a UUID-style id",
  "function": "circuit.core.transform.json",
  "input": {
    "source": "${{ input.id }}",
    "operations": [
      { "type": "substring", "options": { "start": 0, "end": 8 } }
    ]
  },
  "outputs": [
    {
      "name": "short_id",
      "description": "Short id (first 8 bytes of the input id)",
      "value": "${{ extract_short_id.output.transformed_result }}"
    }
  ]
}

Notes & gotchas

  • Errors with substring: expected string if the input is not a string.
  • Indices are byte offsets, not character counts. Slicing through the middle of a multi-byte UTF-8 sequence will panic — pass start and end aligned to character boundaries (typically safe for ASCII strings).
  • start is clamped to [0, len_bytes] and end defaults to len_bytes.
  • For more readable string trimming based on whitespace, see trim / trimStart / trimEnd.
On this page

On this page