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!

56!
link
fedilink
3
edit-2
9M

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.

Create a post

Welcome to the main community in programming.dev! Feel free to post anything relating to programming here!

Cross posting is strongly encouraged in the instance. If you feel your post or another person’s post makes sense in another community cross post into it.

Hope you enjoy the instance!

Rules

Rules

  • Follow the programming.dev instance rules
  • Keep content related to programming in some way
  • If you’re posting long videos try to add in some form of tldr for those who don’t want to watch videos

Wormhole

Follow the wormhole through a path of communities !webdev@programming.dev



  • 1 user online
  • 1 user / day
  • 1 user / week
  • 1 user / month
  • 1.11K users / 6 months
  • 1 subscriber
  • 1.21K Posts
  • 17.8K Comments
  • Modlog