summaryrefslogtreecommitdiff
path: root/.i3/scripts/json_escape.lua
blob: 8723d3e19d4b50f782e83ebaa894d38037b35955 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
function conky_json(str)
    return string.gsub(conky_parse(str), '([\\"])', '\\%1')
end

function conky_i3(...)
    d = "{"
    key = true
    for i,v in ipairs(arg) do
        if key then 
            d = d .. "\"" .. v .. "\":"
            key = false
        else
            d = d .. conky_parse(v)
            if string.sub(v, -1) == '"' then
                if i < table.getn(arg) then d = d .. "," end
                key = true
            else
                d = d .. " "
            end
        end
    end
    return d .. "}"
end