Luadata by Example

Array Mode: Index Only

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:

lua
implicit = {"apple", "banana", "cherry"}
explicit = {
    [1] = "apple",
    [2] = "banana",
    [3] = "cherry",
}
go
reader, err := luadata.TextToJSON("input", input,
    luadata.WithArrayMode("index-only"),
)
output
{
  "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:

bash
luadata tojson --array-mode=index-only input.lua

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