[pshaiCmd] Table to JSON

stable
By pshai in Other Published March 2020 👁 1,634 views 💬 0 comments

Description

Converts InputTable object (or a regular array) to JSON data string.
HaasScript
DefineCommand('TableToJson', 'Converts InputTable to JSON data string')

local inputTable = DefineParameter(ListDynamicType, 'inputTable', 'Table object to be converted', true, {}, 'InputTable')
local tableName = DefineParameter(StringType, 'tableName', 'Name of the table', false, 'table', 'Text, Input, SessionGet, Load')

local ret = '{"'.. tableName .. '":['


for i=1, #inputTable do
    ret = ret .. '['

    for j=1, #inputTable[i] do
        ret = ret .. '"' .. inputTable[i][j] .. '"'
        if j < #inputTable[i] then ret = ret .. ',' end
    end

    ret = ret .. ']'
    if i < #inputTable then ret = ret .. ',' end
end

ret = ret .. ']}'

DefineOutput(StringType, ret, 'The JSON data string', 'ParseJson')

0 Comments

Sign in to leave a comment.

No comments yet. Be the first!