ModelWorks logoModelWorks
JSON TransformString

padEnd

Pad the end of a string to a target length

padEnd

Pads the end of a string with pad_char until its length reaches length bytes. If the string is already long enough, it is returned unchanged.

Options

OptionTypeRequiredDefaultDescription
lengthintegerYesTarget length in bytes.
pad_charstringNo" "Padding string. Empty values fall back to a space.

Example

Input

JSON
"42"

Operation

JSON
{ "type": "padEnd", "options": { "length": 5, "pad_char": "." } }

Output

JSON
"42..."

In a Circuit Step

JSON
{
  "name": "right_pad_label",
  "description": "Right-pad a label with dots to a fixed width",
  "function": "circuit.core.transform.json",
  "input": {
    "source": "${{ input.label }}",
    "operations": [
      { "type": "padEnd", "options": { "length": 20, "pad_char": "." } }
    ]
  },
  "outputs": [
    {
      "name": "padded_label",
      "description": "Label right-padded with dots to 20 bytes",
      "value": "${{ right_pad_label.output.transformed_result }}"
    }
  ]
}

Notes & gotchas

  • Errors with padEnd: expected string if the input is not a string.
  • length is measured in bytes, not characters.
  • pad_char may be longer than one character; it's appended whole-string until the target length is reached, so the output may exceed length if pad_char doesn't divide evenly.
  • An empty pad_char falls back to a single space.
On this page

On this page