Sample code for 30+ languages & platforms
Lua

Load a JSON Array

See more JSON Examples

The Chilkat JSON API requires the top-level JSON to be an object. Therefore, to load an array requires that it first be wrapped as an object.

Chilkat Lua Downloads

Lua
local chilkat = require("chilkat")

local success = false

-- Imagine we want to load this JSON array for parsing:
local jsonArrayStr = "[{\"id\":200},{\"id\":196}]"

-- First wrap it in a JSON object by prepending "{ "array":" and appending "}"
local sbJson = chilkat.StringBuilder.new()
sbJson:append("{\"array\":")
sbJson:append(jsonArrayStr)
sbJson:append("}")

local json = chilkat.JsonObject.new()
json:load(sbJson:get_as_string())

-- Now we can get the JSON array
local jArray = json:array_at(0)

-- Do what you want with the JSON array...
-- For example:
local jObjId = jArray:object_at(0)
print(jObjId:int_of("id"))