Sample code for 30+ languages & platforms
Ruby

Example: JsonObject.NewArrayOf method

See more JSON Examples

Demonstrates the NewArrayOf method.

Chilkat Ruby Downloads

Ruby
require 'chilkat'

success = false

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

json = Chilkat::CkJsonObject.new()

json.UpdateString("test","abc")

success = json.NewArrayOf("big_cats",big_cats)
if (success == false)
    print json.lastErrorText() + "\n";
    exit
end

json.put_EmitCompact(false)
print json.emit() + "\n";

# Result:

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