The "index-only" array mode renders only implicit index tables as JSON arrays. Tables with explicit integer keys always render as objects.
This distinguishes between two ways of writing the same data in Lua:
implicit = {"apple", "banana", "cherry"}
explicit = {
[1] = "apple",
[2] = "banana",
[3] = "cherry",
}
reader, err := luadata.TextToJSON("input", input,
luadata.WithArrayMode("index-only"),
)
{
"implicit": [
"apple",
"banana",
"cherry"
],
"explicit": {
"1": "apple",
"2": "banana",
"3": "cherry"
}
}
The implicit form {"a","b","c"} becomes a JSON array, while the explicit form {[1]="a",[2]="b"} stays as an object.
This is useful when you want to be conservative about array detection and only convert tables that were clearly written with array syntax.
From the CLI:
luadata tojson --array-mode=index-only input.lua
Want more flexibility? Open the interactive converter to try any Lua input with all available options.