JSON to Lua Table

Parses JSON and renders it as a Lua table literal: arrays become positional {1, 2, 3} tables, objects become {key = value, ...} tables with bracket-quoted keys for anything that isn't a valid Lua identifier, matching exactly the syntax subset the Lua to JSON Table tool's parser accepts. A free online tool from Staaarter, right in your browser.

Runs locallyUpdated 2026-07-27

Overview

Introduction

Lua table literals are the native config syntax for game mods, Neovim/LÖVE/Roblox settings, and anything embedding Lua as a data language. This tool goes the other direction from parsing Lua: it takes JSON and writes out the equivalent { key = value, ... } table literal.

It's built as the exact inverse of this site's Lua to JSON Table parser, producing output using only the syntax that parser understands, so the two tools round-trip cleanly.

What Is JSON to Lua Table?

A serializer that walks a parsed JSON value and renders it as Lua table-constructor syntax: JSON arrays become positional tables, JSON objects become key = value tables (with bracket-quoted keys for non-identifier property names), and scalars map to Lua's nil/true/false/numbers/double-quoted strings.

It runs entirely in the browser and doesn't depend on a Lua interpreter or any external library, matching the site's Lua to JSON Table tool's own hand-rolled, no-runtime approach.

How JSON to Lua Table Works

The input is first parsed and validated as JSON with JSON.parse; a syntax error is reported with its line and column before any conversion happens.

The parsed value is then rendered recursively: a JSON array maps to a table with only positional entries, a JSON object maps to a table with only key = value entries (using an identifier-safety check to decide between a bare key and a ["key"] bracket key), and container values recurse into nested tables.

Strings are wrapped in double quotes with backslash escapes for backslash, double quote, newline, tab, and carriage return, the same escape set the Lua to JSON Table tool's tokenizer decodes, so string content round-trips exactly.

When To Use JSON to Lua Table

Use it when you have JSON data (from an API, a config file, a database export) and need it as a Lua table literal for a game mod, a Neovim/LÖVE/Roblox config, or an OpenResty script.

It's also useful for verifying the Lua to JSON Table parser's behavior: convert a JSON value here, then run the Lua output back through that tool to confirm you get an equivalent value back.

Features

Advantages

  • Produces output specifically compatible with this site's Lua to JSON Table parser, so the two tools form a genuine round trip.
  • No external Lua runtime or library dependency; rendering happens with a small hand-written serializer in the browser.
  • Automatically chooses bare identifier keys vs. bracket-quoted keys, so the output is always valid Lua regardless of what the JSON object's keys look like.
  • Handles nested objects and arrays of arbitrary depth, not just a flat top-level structure.

Limitations

  • Only a JSON object or array can be converted, since a Lua table literal always starts with {; a bare top-level scalar is rejected.
  • JSON null becomes Lua's nil literal, but a real Lua runtime treats an assigned nil as removing that key entirely, this tool only produces the literal syntax, it doesn't execute it, so that distinction doesn't apply here.
  • Output uses only the syntax subset the Lua to JSON Table parser supports (no long-bracket strings, no Lua expressions or function calls), which is a safe, portable subset but not exhaustive Lua syntax.

Examples

Object with a nested table and a non-identifier key

Input

{"name":"Ada","age":30,"tags":["admin","editor"],"nested-key":{"x":1}}

Output

{
  name = "Ada",
  age = 30,
  tags = {
    "admin",
    "editor",
  },
  ["nested-key"] = {
    x = 1,
  },
}

"name" and "age" become bare keys, "nested-key" is bracket-quoted since it isn't a valid Lua identifier, and the array becomes a positional table.

Array of strings

Input

["admin","editor"]

Output

{
  "admin",
  "editor",
}

A JSON array with no keys becomes a purely positional Lua table.

Best Practices & Notes

Best Practices

  • Round-trip a converted value back through the Lua to JSON Table tool if you need to confirm the output matches what your Lua environment will parse.
  • Watch for JSON object keys that aren't valid Lua identifiers, they'll appear as bracket-quoted keys in the output, which is valid Lua but reads differently from a bare field name.
  • Remember that JSON null becomes the literal text nil, not an omitted key; adjust by hand if your Lua code expects the key to be entirely absent instead.

Developer Notes

The renderer mirrors the structure of this category's other JSON-to-X-array-literal converters (e.g. json-to-php-array): a recursive render() function keyed on Array.isArray vs. typeof === "object", with an identifier regex (^[A-Za-z_][A-Za-z0-9_]*$) deciding between a bare key = value field and a ["key"] = value bracket field. String escaping mirrors ESCAPE_MAP from lua-to-json-table.ts in reverse, only handling the exact escape set that parser's tokenizer decodes, so encode/decode stay symmetric.

JSON to Lua Table Use Cases

  • Converting an API response or JSON config into a Lua table literal for a game mod, Neovim plugin, or LÖVE project.
  • Generating Roblox or OpenResty configuration data from an existing JSON source of truth.
  • Round-trip testing the Lua to JSON Table parser against arbitrary JSON structures.
  • Migrating JSON-based configuration into a Lua-based configuration format.

Common Mistakes

  • Pasting a top-level JSON string, number, boolean, or null directly; only an object or array converts, since a Lua table literal requires a surrounding {.
  • Assuming the output is executable Lua code beyond the table literal itself; it's just the { ... } constructor, not a full script with variable assignment.
  • Expecting numeric-looking JSON object keys (like "1") to become Lua array entries; they still render as ["1"] = value bracket-keyed fields, since JSON object keys are always strings.

Tips

  • If the output looks unexpectedly bracket-heavy, check your JSON object's key names, hyphens, spaces, and leading digits all force bracket-quoted keys.
  • Use the JSON Formatter first if your source JSON is minified and hard to review before converting.
  • For hex-style Lua numbers, this tool always emits plain decimal, since JSON numbers have no hex literal form to preserve.

References

Frequently Asked Questions