Why JSON
Data interchange basics.
What Is JSON?
JSON (JavaScript Object Notation) is a lightweight text format for storing and exchanging data. It is human-readable and language-independent.
Almost every web API, config file, and database speaks JSON. Learning to convert between JSON and Lua tables lets your scripts talk to the outside world.
JSON Looks Like Lua
JSON objects use curly braces with key-value pairs, and arrays use square brackets. This maps almost perfectly onto Lua tables.
A JSON object becomes a Lua table with string keys; a JSON array becomes a Lua table with numeric indices starting at 1.
-- JSON text
-- {"name": "Ada", "age": 36}
-- Equivalent Lua table
local person = { name = "Ada", age = 36 }
print(person.name)