r/lua • u/Suspicious_Anybody78 • Dec 10 '25
Project ion (JSON Inspired Data Format)
I've spent quite some time attempting to perfect this simple module, and have today decided to attempt to share it. I do not doubt the coding might not be very good, but I at least hope it performs what it's designed for, and that's storing a table using as many space saving shortcuts as possible. I also do not expect it to be perfect at what it tries to achieve either.
There are 3 goals primary goals in mind:
- Keeping the format lean, for the most part.
- Keeping it mostly human readable.
- Having support for the vast majority of types of Lua tables, with exception of functions.
There's example code here, but I will still provide some simple example usage.
local ion = require("ion") -- for getting the module
local database = {"Bob","Mary"}
ion.Create(database,"database")The resulting created ion will look like this:
|ion{
1|Bob
2|Mary
}And, it can be turned back into a table like so:
local ion = require("ion")
local database = ion.Read("database.ion")ion.Create() in particular has a lot more parameters for fine tuning what gets written to the resulting ion, but for now that's all this post needs I suppose.
The GitHub Pages Site:
View all comments
Show parent comment
1
u/Suspicious_Anybody78 Dec 12 '25 edited Dec 12 '25
Strings already can contain those symbols. : and { both get detected properly in a way to avoid needing to escape them, and | is escaped with \.
For further reference, just in case:
The module uses the basic logic that there does not exist a non-string literal that is capable of containing another colon. So if the attempt to resolve it as a string fails, then it just looks for the final instance of a colon and cuts off everything at the colon and after to extract the value.
For string literals, it just looks for (as of 2.0.0) a pipe that is preceded by a character that is not a backslash, and cuts off everything after the character that is not a backslash.