JSON to Lua Converter
Turn JSON data into a Lua table literal
JSON Input
Lua Output
What does the JSON to Lua converter do?
Sometimes you don't want to parse JSON at runtime at all; you just want the data sitting in a Lua file. Game mods, Neovim and WezTerm configs, and test fixtures are good examples. Paste JSON here and you get a single local rootObject = { ... } assignment written with table constructors: objects become keyed tables, arrays become sequences, true/false stay booleans and null becomes nil.
Keys that are valid Lua names are written bare (plan = "Unlimited 5G"). Everything else, including keys with spaces or dashes and Lua keywords like end, function or local, is written as ["end"] = 1, so the file always parses. Strings are escaped backslash first, then quotes, newlines, tabs and control characters, using escapes that Lua 5.1 through 5.4 all accept.
Numbers get some care. Integers past 2^53 are read without rounding and written as plain literals, which are exact in Lua 5.3 and later (Lua 5.1 and LuaJIT store every number as a double and will round them; a comment in the output says so). Integers too big for a 64-bit Lua integer are kept as strings. A JSON string that only contains digits, like an ICCID sent as text, stays a string. There are no metatables or helper functions in the output, just data. It all runs in your browser.
How to use it
The table updates as you type.
Paste JSON
Paste into the JSON Input panel, Upload a .json or .txt file, or click Sample. Example input:
{"subscriberId":"SUB-1001","plan":"Unlimited 5G","dataUsage":45.2,"status":"active"}Table Name sets the variable name (characters Lua doesn't allow are replaced with underscores). If the input won't parse, run it through the JSON Validator.
Check the table
The Lua Output panel shows the table, indented two spaces per level. If an array contained null, a comment warns you that the resulting nil leaves a hole, so #t and ipairs stop early there.
Copy or download
Copy it, or Download a .lua file. Add return rootObject at the end if you want to load it with require or dofile.
Where this saves time
Game mods and level data
Item lists or level definitions exported from a tool as JSON can live in a Lua file your mod loads directly, with no JSON library in the game runtime.
Editor and terminal configs
Moving settings from a JSON-based editor to Neovim or WezTerm? Convert the settings object and paste the table into your Lua config.
Test fixtures
Paste an API response and use it as a fixture in busted or another Lua test framework instead of reading and decoding a file in every test.
Seeing what a decoder will give you
Libraries like lua-cjson turn JSON into tables at runtime. Converting a sample here shows the shape you'll be indexing, nil holes included.
Common Questions
Which Lua versions does the output work with?
The syntax works in Lua 5.1 through 5.4 and LuaJIT. The only version difference is numbers: integers past 2^53 are exact in Lua 5.3+ but get rounded by 5.1 and LuaJIT, and the output adds a comment when that applies.
How are JSON null values handled?
They become nil. In an object that simply means the key is absent. In an array it leaves a hole, which breaks # and ipairs, so the output warns you when that happens. Use a sentinel value if you need to keep the position.
Can I tell empty objects from empty arrays?
No. Both {} and [] become an empty Lua table {}, because Lua uses one type for both.
Why are some keys in brackets?
Only names made of letters, digits and underscores that aren't Lua keywords can be written bare. Keys like first name, user-id or end are written as ["first name"] so the table still parses.
Is my JSON uploaded?
No. The table is generated by JavaScript in your browser and nothing is sent to a server. Input is capped at 256 KB.
Other JSON Tools You Might Need
Need the data as typed code instead of a table, or want to tidy the JSON first?