You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Daniel Flassig edited this page May 6, 2025
·
10 revisions
Parses a json file to a basic Lua data structure.
pyio.parse_json(file)
Parameter
Type
Description
file
file handle
The file that should be read
Return value
json-Type
Lua equivalent
json object {...}
Lua table with string-keys (see example)
json array [...]
Lua table with integer indices starting at 1(!)
json string "..."
Lua string
json number
Lua number
json true, false, null
Lua true, false, nil
Example:
For example, a text file with the following content
{
"Type" : "TEST",
"My Numbers" : [1, 2, 3.5]
}
would result in the following lua tables
{
Type="Test",
["My Numbers"] = {1, 2, 3.5}
}
Remarks:
Interestingly, json can be mapped quite easily to the data types available in Lua. Please note, however, that the json array indices t = ["a", "b"] would be 0-based when accessed in javascript (i.e. t[0] = "a"; t[1] = "b";). Whereas the resulting table in Lua t_lua = {"a", "b"} has 1-based indices (i.e. t_lua[1] = "a"; t_lua[2] = "b";).