cross-posted from: https://lemmy.nz/post/4294116
I have a file with content like this:
item({ ["attr"] = { ["size"] = "62091"; ["filename"] = "qBuUP9-OTfuzibt6PQX4-g.jpg"; ["stamp"] = "2023-12-05T19:31:37Z"; ["xmlns"] = "urn:xmpp:http:upload:0"; ["content-type"] = "image/jpeg"; }; ["key"] = "Wa4AJWFldqRZjBozponbSLRZ"; ["with"] = "email@address"; ["when"] = 1701804697; ["name"] = "request"; });
I need to know what format this is, and if there exists a tool in linux already to parse this or if I need to write one myself?
Thanks!
You must log in or register to comment.
I think it’s just normal Lua code.
Here’s a quick json converter (based on https://stackoverflow.com/a/55575074), assuming you have lua installed:
local function to_json(obj) local result = {} for key, value in pairs(obj) do if type(value) == "string" then value = string.format("\"%s\"", value) elseif type(value) == "table" then value = to_json(value) end table.insert(result, string.format("\"%s\":%s", key, value)) end return "{" .. table.concat(result, ",") .. "}" end function item(obj) print(to_json(obj)) end dofile(arg[1])
It just defines the
item
function to print json, and executes the data file.arg[1]
, the first command line argument, is the path to the data file:$ lua to_json.lua path/to/datafile.list
and pipe the output to
something.json
or whatever else you want to do.Almost looks like mongodb output. What’s the file extension?
It’s .list
I believe the program that generated this file is written in Lua