Sample code for 30+ languages & platforms
Ruby

JSON AppendArray2 Example

Demonstrates the AppendArray2 function.

Chilkat Ruby Downloads

Ruby
require 'chilkat'

json = Chilkat::CkJsonObject.new()
json.Load("{ \"name\": \"John\", \"marbles\": 100 }")

# Append an empty array named "xyz"
jarr = Chilkat::CkJsonArray.new()
json.AppendArray2("xyz",jarr)

print json.emit() + "\n";
# Expected output is:   {"name":"John","marbles":100,"xyz":[]}

# Add elements to the array.
jarr.AddStringAt(-1,"hello")
jarr.AddIntAt(-1,256)

print json.emit() + "\n";
# Expected output is:  {"name":"John","marbles":100,"xyz":["hello",256]}