JSON to Lua Converter
About this tool
Lua table syntax vs JSON
While JSON and Lua tables share a visual resemblance -- both use curly braces for structured data -- there are important syntactic and semantic differences. JSON distinguishes between objects (key-value maps with curly braces) and arrays (ordered lists with square brackets), whereas Lua uses a single table construct for both. In Lua, string keys are written as ["key"] = value or, when the key is a valid identifier, simply key = value. Array elements in Lua are indexed starting at 1, not 0 as in most other languages. JSON has a dedicated null type; Lua uses nil, which actually removes a key from a table rather than storing an explicit null marker. JSON requires double-quoted strings exclusively, while Lua supports both single and double quotes as well as long bracket strings for multiline text. Booleans and numbers map directly between the two formats with no conversion needed.
Conversion rules
This tool applies a deterministic set of rules when transforming JSON into Lua table syntax. JSON objects become Lua tables with explicit string keys using bracket notation, preserving the original key names exactly. JSON arrays become Lua tables with implicit sequential numeric indices starting at 1, listed as comma-separated values. The JSON null value maps to Lua nil. JSON booleans (true and false) transfer directly since Lua supports the same literals. JSON numbers, including integers and floating-point values, are emitted unchanged. JSON strings are wrapped in Lua double-quote string literals with appropriate escaping for special characters. Nested structures are handled recursively, and the output is indented with consistent spacing to reflect nesting depth.
Related tools: JSON Formatter, JSON to TypeScript Converter
Frequently Asked Questions
How do I convert JSON to a Lua table?
To convert JSON to a Lua table, paste your raw JSON data into the left input panel. The converter parses the JSON using the browser's native JSON.parse() method and then recursively transforms each value into its Lua equivalent. The resulting Lua table syntax appears instantly in the right output panel with proper indentation for readability. Once the conversion is complete, click the copy button in the output panel header to copy the Lua code to your clipboard. The converter supports all standard JSON types: objects become Lua tables with string keys, arrays become tables with sequential numeric indices starting at 1, strings are wrapped in double quotes, numbers and booleans transfer directly, and null values become nil. You can use the output directly in Lua scripts, configuration files for game engines like Love2D or Defold, or embedded Lua environments such as Redis scripting and Nginx OpenResty.
What is Lua table syntax?
Lua tables are the sole data structuring mechanism in Lua, serving as both arrays and dictionaries. A table is defined with curly braces and can contain key-value pairs written as ["key"] = value for string keys or simply key = value when the key is a valid Lua identifier. Numeric array entries use sequential indices starting at 1, unlike most languages that start at 0. Nested tables are supported by placing a table literal as a value inside another table. For example, a JSON object like {"name": "test", "tags": [1, 2]} becomes {["name"] = "test", ["tags"] = {1, 2}} in Lua table syntax. Tables can also mix numeric and string keys in the same structure. The nil value represents the absence of data and effectively removes a key from a table when assigned. This flexibility makes Lua tables suitable for representing complex hierarchical data parsed from JSON.
Does this handle nested JSON?
Yes, this converter fully supports arbitrarily deep nesting of JSON objects and arrays. Each nested JSON object is converted into a nested Lua table with properly quoted string keys, and each nested JSON array becomes a Lua table with sequential numeric indices. The output is automatically indented to reflect the nesting depth, making even complex structures easy to read. For example, a three-level deep JSON structure with mixed objects and arrays will produce a Lua table with matching indentation at every level. The converter also correctly handles edge cases such as empty objects (converted to empty Lua tables {}), empty arrays (also empty tables), null values within nested structures (converted to nil), and arrays containing objects or other arrays. There is no artificial depth limit imposed by the tool. Performance depends on browser memory and the size of the input document, but typical JSON payloads of several megabytes convert without issues.