Sample code for 30+ languages & platforms
Swift

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

Swift

func chilkatTest() {
    let arr1 = CkoJsonArray()!
    let arr2 = CkoJsonArray()!

    var s: String? = "[{\"a\":1}, {\"b\":2}, {\"c\":3}]"
    var sEmpty: String? = "[]"

    arr1.load(jsonArray: s)
    arr2.load(jsonArray: sEmpty)

    let jObj = CkoJsonObject()!
    arr1.objectAt2(index: 1, jsonObj: jObj)

    arr2.addObjectCopy(at: -1, jsonObj: jObj)

    print("\(arr2.emit()!)")

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

}