Luadata by Example

String Transform Modes

There are four modes for handling strings that exceed MaxLen. All examples below use MaxLen of 10 on this input:

lua
data = "hello world, this is a long string"

Truncate (default) cuts the string to the max length:

json
{
  "data": "hello worl"
}

Empty replaces the string with an empty string:

json
{
  "data": ""
}

Redact replaces the string with "[redacted]":

json
{
  "data": "[redacted]"
}

Replace uses a custom replacement string:

go
reader, err := luadata.TextToJSON("input", input,
    luadata.WithStringTransform(10, "replace", "<too long>"),
)
json
{
  "data": "<too long>"
}

From the CLI, use the --string-max-len and --string-mode flags:

bash
luadata tojson --string-max-len=10 --string-mode=redact input.lua

For the replace mode, add --string-replacement:

bash
luadata tojson --string-max-len=10 --string-mode=replace --string-replacement="<too long>" input.lua

Want more flexibility? Open the interactive converter to try any Lua input with all available options.