JSON to Lua Table Syntax Converter — Free Online Tool
Convert JSON to Lua table syntax using AI. Produces idiomatic Lua tables with correct string quoting, nested tables, and array-style integer keys. Free, no sign-up.
JSON to Lua Table Syntax Converter — Free Online Tool
About JSON to Lua Table Syntax Converter — Free Online Tool
JSON to Lua Table converter transforms JSON objects, arrays, strings, numbers, booleans, and null values into valid Lua table constructor syntax, handling nested structures and special characters in keys. Developers use it when integrating external APIs, configuration files, or data pipelines into Lua-based environments such as Roblox, LÖVE 2D, Neovim plugins, or game engines like Corona SDK.
JSON to Lua Type Mapping
| JSON Type | JSON Example | Lua Equivalent | Lua Example | Notes |
|---|---|---|---|---|
| Object | {"x": 1} | Table (hash part) | {x = 1} | String keys become bare identifiers when valid; otherwise ["key"] syntax is used |
| Array | [1, 2, 3] | Table (sequence part) | {1, 2, 3} | 1-indexed; JSON index 0 maps to Lua index 1 |
| String | "hello" | string | "hello" | Embedded quotes and backslashes are escaped |
| Number (integer) | 42 | integer / number | 42 | Lua 5.3+ distinguishes integers; earlier versions use a single number type |
| Number (float) | 3.14 | number (float) | 3.14 | NaN and Infinity are not valid JSON and have no direct Lua literal; convert to nil or string |
| Boolean true | true | boolean | true | Direct mapping — same keyword |
| Boolean false | false | boolean | false | Direct mapping — same keyword |
| Null | null | nil | nil | Lua tables cannot store nil values as meaningful entries; key is typically omitted |
Lua Table Syntax vs Other Config/Data Formats
| Feature | Lua Table | JSON | TOML | YAML |
|---|---|---|---|---|
| File extension | .lua | .json | .toml | .yaml / .yml |
| Comment support | -- single, --[[ block ]] | None (standard) | # inline | # inline |
| Trailing commas | Allowed | Not allowed | Allowed | N/A |
| String delimiters | " or ' or [[ ]] | " only | " or ''' multi-line | " or ' or bare |
| Integer vs float distinction | Yes (Lua 5.3+) | No | Yes | No |
| Null / missing value | nil (omit key) | null | No null type | null or ~ |
| Mixed array+hash tables | Yes (same table) | Separate object/array | Array of tables | Sequence + mapping separate |
| Native executable | Yes (Lua scripts) | No | No | No |
| Human editable | Yes | Yes (no comments) | Yes | Yes |
Frequently Asked Questions
How does JSON null convert to Lua?
JSON null maps to Lua's nil, but nil cannot be stored as a table value in Lua — assigning t[key] = nil removes the key from the table entirely. Most converters either omit null-valued keys from the output or replace them with a sentinel string like "null" or a false boolean, depending on your use case. If you need to preserve the distinction between a missing key and an explicit null, use a placeholder constant such as json_null = {} and assign that instead.
Why does my JSON array start at index 1 in the Lua table?
Lua sequences are 1-indexed by convention, whereas JSON arrays are 0-indexed. A JSON array ["a", "b", "c"] becomes {"a", "b", "c"} in Lua, where "a" is at index 1. If your Lua code iterates with ipairs or uses the # length operator it will work correctly, but any logic that assumed 0-based access must be updated. The converter handles this remapping automatically.
How are JSON object keys with spaces or special characters handled in Lua tables?
Lua bare identifiers cannot contain spaces, hyphens, or start with a digit, so keys like "my-key" or "2fast" must use bracket notation: ["my-key"] = value and ["2fast"] = value. Valid identifier keys (alphanumeric plus underscore, not starting with a digit) are emitted as bare keys for readability, e.g. myKey = value. The converter automatically detects which form to use for each key.
Can I use the converted Lua table directly in Roblox or LÖVE 2D?
Yes. Both Roblox (Luau) and LÖVE 2D use Lua-compatible table syntax. After converting, paste the output into a .lua module file and return the table, e.g. return { ... }. In Roblox you can also use a ModuleScript and require() it. The only Roblox-specific caveat is that Luau enforces type annotations optionally, so large converted tables may benefit from an explicit type alias.
What happens to deeply nested JSON objects in Lua table output?
Nested JSON objects become nested Lua table constructors with consistent indentation. For example, {"a": {"b": 1}} converts to { a = { b = 1 } }. There is no depth limit in the syntax itself, but Lua has a default C stack depth limit (~200 levels) for table construction at runtime. Extremely deep nesting (hundreds of levels) is unusual in practice and would indicate a data-design issue rather than a converter limitation.
If jsondecode.com saved you time, share it with your team
Free forever. No ads. No sign-up. Help other developers find it.