JSON TransformString
padStart
Pad the start of a string to a target length
padStart
Pads the beginning of a string with pad_char until its length reaches length bytes. If the string is already long enough, it is returned unchanged.
Options
| Option | Type | Required | Default | Description |
|---|---|---|---|---|
length | integer | Yes | — | Target length in bytes. |
pad_char | string | No | " " | Padding string. Empty values fall back to a space. |
Example
Input
"42"Operation
{ "type": "padStart", "options": { "length": 5, "pad_char": "0" } }Output
"00042"In a Circuit Step
{
"name": "zero_pad_id",
"description": "Left-pad a numeric id with zeros to a fixed width",
"function": "circuit.core.transform.json",
"input": {
"source": "${{ input.id_string }}",
"operations": [
{ "type": "padStart", "options": { "length": 8, "pad_char": "0" } }
]
},
"outputs": [
{
"name": "padded_id",
"description": "Id zero-padded to 8 bytes",
"value": "${{ zero_pad_id.output.transformed_result }}"
}
]
}Notes & gotchas
- Errors with
padStart: expected stringif the input is not a string. lengthis measured in bytes, not characters. Multi-bytepad_charvalues can produce unexpectedly long output.pad_charmay be longer than one character; it's repeated whole-string until the target length is reached. Each iteration appends the fullpad_char, so the output may exceedlengthifpad_chardoesn't divide evenly.- An empty
pad_charfalls back to a single space.