Lua to JSON Converter
About this tool
Converting Lua tables back to JSON
Lua table literals and JSON documents look alike but differ in ways that make a naive find-and-replace unreliable. Lua wraps every structured value in curly braces, using one table type where JSON separates objects from arrays with distinct bracket styles. Lua string keys can be written bare as key = value when they are valid identifiers, or in bracket form as ["key"] = value when they contain hyphens, spaces, or reserved words; JSON always quotes keys. Lua array indices start at 1, JSON arrays start at 0. Lua accepts single quotes, double quotes, and long bracket strings such as [[multi-line text]]; JSON permits only double quotes. Lua allows comma or semicolon separators between entries and tolerates a trailing separator; JSON allows neither. Lua files carry comments, JSON has none. This converter handles each of those differences during parsing so the JSON it emits is valid without any manual cleanup.
Where Lua data comes from
Lua tables turn up as configuration and data files across a wide range of runtimes, and moving that data into a JSON pipeline is the usual reason to convert. Neovim and Wireshark plugins keep their settings in Lua tables. Game engines including Love2D, Defold, Roblox, and Garry's Mod use Lua tables for level data, entity definitions, and localisation strings. Nginx and OpenResty configuration scripts build request-routing tables in Lua. Redis scripting returns Lua tables from EVAL. World of Warcraft addons store saved variables as large Lua table dumps. In each case the data is already structured, so converting it to JSON makes it consumable by tooling that does not embed a Lua interpreter — jq, spreadsheet importers, HTTP APIs, or a schema validator.
Related tools: JSON to Lua Converter, JSON Formatter, JSON Query
Frequently Asked Questions
How do I convert a Lua table to JSON?
Paste your Lua table into the left input panel. The converter parses the Lua table literal directly in your browser and emits the equivalent JSON in the right output panel, then you can click the copy button in the output header to copy it. You can paste a bare table such as {a = 1, b = 2}, or a full module file that starts with return {...}, local config = {...}, or M.settings = {...} — the leading assignment is detected and skipped automatically. Both identifier keys (key = value) and bracketed keys (["key"] = value, [3] = value) are supported, as are semicolon separators, trailing separators, single and double quoted strings, long bracket strings such as [[text]] and [==[text]==], line comments beginning with --, and block comments written as --[[ ... ]]. Because the conversion is a pure parse with no evaluation, no data ever leaves your browser and there is no server round trip.
How are Lua tables mapped to JSON arrays versus objects?
Lua uses a single table type for both arrays and maps, so the converter has to decide which JSON shape fits. A table becomes a JSON array only when its keys form the contiguous integer sequence 1 through n that Lua itself treats as a sequence. That covers the common cases: positional entries such as {10, 20, 30} and explicitly numbered entries such as {[1] = "a", [2] = "b"}. Anything else becomes a JSON object with the keys converted to strings. That includes tables with string keys, tables whose numeric keys start at 0, sparse tables such as {[1] = "a", [5] = "b"}, and mixed tables such as {"a", "b", name = "x"} where the positional entries appear as "1" and "2" alongside the named key. Preferring an object in ambiguous cases means no entry is ever silently discarded, which is what would happen if a sparse table were flattened into an array.
What happens to nil values?
A nil value in a Lua table is converted to JSON null. Strictly speaking this is not a round trip: assigning nil to a key in real Lua removes that key from the table, so a literal such as {value = nil} describes a table with no value key at all. JSON has no equivalent removal semantics, and dropping the key silently would hide information from anyone inspecting the output, so the converter keeps the key and represents the absence with null. If you want the key gone entirely, delete it from the JSON output after converting. Booleans and numbers map directly since both formats share the same literals, and Lua numbers written in hexadecimal (0xff), with a decimal point (3.14), or in scientific notation (314.16e-2) are all normalised to standard JSON numbers.
Why does my Lua table fail to convert?
This tool is a literal parser, not a Lua interpreter, so it accepts data but rejects code. Anything that would require evaluation is reported as an error with the line number rather than being guessed at: function calls such as os.time(), arithmetic such as 1 + 2, string concatenation with .., variable references, and function definitions. Structural mistakes are reported the same way, including unterminated tables, unterminated strings, unbalanced long brackets, and invalid escape sequences. If your file mixes data and logic, extract just the table literal and convert that. If you need the reverse direction, the JSON to Lua converter turns JSON documents back into Lua table syntax.