json-set.lua (386B)
1 local json = require "json" 2 3 local myarg = { } 4 for s in string.gmatch(args, "%S+") do 5 myarg[#myarg+1] = s 6 end 7 local file = myarg[1] 8 local var = myarg[2] 9 local val = myarg[3] 10 11 local f = io.open(file, "rb") 12 local js = f:read("*all") 13 f:close() 14 local t = json.decode(js) 15 t[var] = val 16 17 f = io.open(file, "w") 18 f:write(json.encode(t)) 19 f:close() 20 21 return "Setting " .. var .. " to " .. val