What is JSON to Lua Table Generator?
Lua is a lightweight scripting language embedded in games (Roblox, World of Warcraft), Nginx, Redis, and Neovim, where tables serve as the universal data structure — they function as both arrays and dictionaries simultaneously. Converting JSON to Lua tables lets you embed configuration data directly into Lua scripts without requiring a JSON parser at runtime. This tool maps JSON types to their Lua equivalents: strings become quoted Lua strings, numbers become unquoted numeric literals, booleans become the true and false keywords, null becomes nil, arrays become integer-keyed tables, and objects become string-keyed tables. The output includes proper indentation, optional type annotation comments, and correct string escaping for the Lua runtime.
How to Use
- Set the variable name for the generated Lua table in the options above
- Paste your JSON object into the input area — only objects are supported, not arrays
- Toggle type annotation comments to add inline type hints after each value
- Click "Generate" to produce the Lua table definition
- Copy the output into your Lua script, Neovim config, or Redis Lua module
Why Use This Tool?
Tips & Best Practices
- Lua tables use 1-based indexing for arrays — be aware of this when consuming the generated table in loops
- Boolean values map to Lua true and false keywords, not quoted strings
- Null values become nil in Lua — note that nil values in tables effectively remove the key
- String keys that are valid Lua identifiers are left unquoted; keys with special characters are bracket-quoted
- Enable type annotations when generating config files for Neovim or game scripts to improve readability
Frequently Asked Questions
How are JSON types mapped to Lua types?
JSON strings become quoted Lua strings, integers and floats become unquoted Lua number literals, booleans map to the Lua true and false keywords, null becomes nil, arrays become Lua tables with implicit integer keys, and objects become Lua tables with string keys. The type mapping preserves the semantic meaning of each value.
When should I NOT use Lua tables for JSON data?
Avoid converting JSON to Lua tables when you need to preserve the exact JSON structure for round-trip serialization — Lua tables do not distinguish between an array and a dictionary with integer keys. Also avoid this for very large JSON files where a streaming JSON parser would be more memory-efficient than loading the entire structure as a Lua table.
Does this tool handle nested JSON structures?
Yes, nested JSON objects and arrays are converted into nested Lua tables with proper indentation. Each level of nesting is indented with two spaces for readability. There is no practical limit on nesting depth.
What are type annotation comments?
When enabled, the tool adds Lua comments after each value indicating its inferred type (e.g., -- string, -- integer, -- number, -- boolean, -- table, -- nil). This helps with code readability and serves as lightweight documentation for configuration files.
How are arrays represented in Lua?
In Lua, arrays are represented as tables with implicit integer keys starting from 1. The generated code uses the shorthand syntax {val1, val2, ...} which is equivalent to {[1]=val1, [2]=val2, ...}. Note that Lua uses 1-based indexing, not 0-based.
Is my data sent to a server?
No, all processing happens entirely in your browser. Your JSON data never leaves your device. No data is collected, logged, or transmitted to any server.
Real-world Examples
Neovim plugin configuration
Convert a JSON plugin configuration into a Lua table for use in a Neovim init.lua file.
{
"colorscheme": "catppuccin",
"line_numbers": true,
"tab_size": 2
}local config = { -- table
colorscheme = "catppuccin", -- string
line_numbers = true, -- boolean
tab_size = 2, -- integer
}
return configGame data table for Roblox
Convert a JSON item database into a Lua table for a Roblox game script.
{
"sword": {"damage": 25, "speed": 1.5},
"shield": {"damage": 0, "speed": 0.8}
}local items = { -- table
sword = { -- table
damage = 25, -- integer
speed = 1.5, -- number
},
shield = { -- table
damage = 0, -- integer
speed = 0.8, -- number
},
}
return items