Sample code for 30+ languages & platforms
Lua Requires Chilkat v11.4.0+

Example: JsonObject.NewArrayOf method

See more JSON Examples

Demonstrates the NewArrayOf method.

Chilkat Lua Downloads

Lua
local chilkat = require("chilkat")

local big_cats = "[\"lion\",\"tiger\",\"leopard\",\"jaguar\",\"cheetah\",\"snow leopard\",\"clouded leopard\",\"cougar\",\"puma\",\"panther\"]"

local json = chilkat.JsonObject.new()

json:update_string("test", "abc")

local success = json:new_array_of("big_cats", big_cats)
if not success then
    print(json.last_error_text)
    return
end

json.emit_compact = false
print(json:emit())

-- Result:

-- {
--   "test": "abc",
--   "big_cats": [
--     "lion",
--     "tiger",
--     "leopard",
--     "jaguar",
--     "cheetah",
--     "snow leopard",
--     "clouded leopard",
--     "cougar",
--     "puma",
--     "panther"
--   ]
-- }