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
| Option | Type | Required | Default | Description |
|---|---|---|---|---|
start | integer | Yes | — | Inclusive start index, in bytes. |
end | integer | No | string length | Exclusive end index, in bytes. |
Example
Input
"hello world"Operation
{ "type": "substring", "options": { "start": 6, "end": 11 } }Output
"world"In a Circuit Step
{
"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 stringif 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
startandendaligned to character boundaries (typically safe for ASCII strings). startis clamped to[0, len_bytes]andenddefaults tolen_bytes.- For more readable string trimming based on whitespace, see
trim/trimStart/trimEnd.