Lua Requires Chilkat v11.4.0+
Lua
Example: JsonObject.NewArrayOf method
See more JSON Examples
Demonstrates theNewArrayOf method.
Chilkat Lua Downloads
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"
-- ]
-- }