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

JSON AppendArray2 Example

Demonstrates the AppendArray2 function.

Chilkat Lua Downloads

Lua
local chilkat = require("chilkat")

local json = chilkat.JsonObject.new()
json:load("{ \"name\": \"John\", \"marbles\": 100 }")

-- Append an empty array named "xyz"
local jarr = chilkat.JsonArray.new()
json:append_array2("xyz", jarr)

print(json:emit())
-- Expected output is:   {"name":"John","marbles":100,"xyz":[]}

-- Add elements to the array.
jarr:add_string_at(-1, "hello")
jarr:add_int_at(-1, 256)

print(json:emit())
-- Expected output is:  {"name":"John","marbles":100,"xyz":["hello",256]}