A Lua library for encoding and decoding TOML file formats to/from JSON and Lua tables.
To use this library in your Lua project, simply include the toml_encoder_decoder.lua
file in your project and require it in your code.
local toml = require("toml_encoder_decoder")
Encode Lua tables or JSON strings to TOML.
local luaTable = { key1 = "value1", key2 = { nestedKey = "nestedValue" } }
local tomlString = toml.encode(luaTable)
local jsonString = '{"key1":"value1","key2":{"nestedKey":"nestedValue"}}'
local tomlString = toml.encode(jsonString, { format = "json" })
Decode TOML strings to Lua tables or JSON strings.
local tomlString = 'key1 = "value1"\n[key2]\nnestedKey = "nestedValue"'
local luaTable = toml.decode(tomlString)
local jsonString = '{"key1":"value1","key2":{"nestedKey":"nestedValue"}}'
local luaTable = toml.decode(jsonString, { format = "json" })
local toml = require("toml_encoder_decoder")
-- Encoding
local luaTable = { key1 = "value1", key2 = { nestedKey = "nestedValue" } }
local tomlString = toml.encode(luaTable)
print("Encoded TOML:")
print(tomlString)
-- Decoding
local decodedTable = toml.decode(tomlString)
print("\nDecoded Lua Table:")
for key, value in pairs(decodedTable) do
print(key, value)
end
Feel free to contribute to this project. Fork it, make changes, and create a pull request. Any contributions are welcome!
This library is open-sourced under the MIT License.