Lua Requires Chilkat v11.0.0+
Lua
Copy JSON Object from one JSON Array to Another
See more JSON Examples
Demonstrates how to copy an object in a JSON array to another JSON array.Chilkat Lua Downloads
local chilkat = require("chilkat")
local arr1 = chilkat.JsonArray.new()
local arr2 = chilkat.JsonArray.new()
local s = "[{\"a\":1}, {\"b\":2}, {\"c\":3}]"
local sEmpty = "[]"
arr1:load(s)
arr2:load(sEmpty)
local jObj = chilkat.JsonObject.new()
arr1:object_at2(1, jObj)
arr2:add_object_copy_at(-1, jObj)
print(arr2:emit())
-- output is: [{"b":2}]