(Tcl) Create a JSON Array of Objects
Demonstrates how to create a JSON array of objects.
load ./chilkat.dll
set arr [new_CkJsonArray]
# Add an empty object at the 1st JSON array position.
CkJsonArray_AddObjectAt $arr 0
# Get the object we just created.
# obj is a CkJsonObject
set obj [CkJsonArray_ObjectAt $arr 0]
CkJsonObject_UpdateString $obj "Name" "Otto"
CkJsonObject_UpdateInt $obj "Age" 29
CkJsonObject_UpdateBool $obj "Married" 0
delete_CkJsonObject $obj
# Add an empty object at the 2nd JSON array position.
CkJsonArray_AddObjectAt $arr 1
set obj [CkJsonArray_ObjectAt $arr 1]
CkJsonObject_UpdateString $obj "Name" "Connor"
CkJsonObject_UpdateInt $obj "Age" 43
CkJsonObject_UpdateBool $obj "Married" 1
delete_CkJsonObject $obj
# Add an empty object at the 3rd JSON array position.
CkJsonArray_AddObjectAt $arr 2
set obj [CkJsonArray_ObjectAt $arr 2]
CkJsonObject_UpdateString $obj "Name" "Ramona"
CkJsonObject_UpdateInt $obj "Age" 34
CkJsonObject_UpdateBool $obj "Married" 1
delete_CkJsonObject $obj
# Examine what we have:
CkJsonArray_put_EmitCompact $arr 0
puts [CkJsonArray_emit $arr]
# The output is:
# [
# {
# "Name": "Otto",
# "Age": 29,
# "Married": false
# },
# {
# "Name": "Connor",
# "Age": 43,
# "Married": true
# },
# {
# "Name": "Ramona",
# "Age": 34,
# "Married": true
# }
# ]
delete_CkJsonArray $arr
|