Sample code for 30+ languages & platforms
Tcl

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 Tcl Downloads

Tcl

load ./chilkat.dll

set arr1 [new_CkJsonArray]

set arr2 [new_CkJsonArray]

set s "[{\"a\":1}, {\"b\":2}, {\"c\":3}]"
set sEmpty "[]"

CkJsonArray_Load $arr1 $s
CkJsonArray_Load $arr2 $sEmpty

set jObj [new_CkJsonObject]

CkJsonArray_ObjectAt2 $arr1 1 $jObj

CkJsonArray_AddObjectCopyAt $arr2 -1 $jObj

puts [CkJsonArray_emit $arr2]

# output is:   [{"b":2}]

delete_CkJsonArray $arr1
delete_CkJsonArray $arr2
delete_CkJsonObject $jObj