Sample code for 30+ languages & platforms
DataFlex

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

DataFlex
Use ChilkatAx-win32.pkg

Procedure Test
    Handle hoArr1
    Handle hoArr2
    String s
    String sSEmpty
    Boolean iSuccess
    Variant vJObj
    Handle hoJObj
    String sTemp1

    Get Create (RefClass(cComChilkatJsonArray)) To hoArr1
    If (Not(IsComObjectCreated(hoArr1))) Begin
        Send CreateComObject of hoArr1
    End
    Get Create (RefClass(cComChilkatJsonArray)) To hoArr2
    If (Not(IsComObjectCreated(hoArr2))) Begin
        Send CreateComObject of hoArr2
    End

    Move '[{"a":1}, {"b":2}, {"c":3}]' To s
    Move "[]" To sSEmpty

    Get ComLoad Of hoArr1 s To iSuccess
    Get ComLoad Of hoArr2 sSEmpty To iSuccess

    Get Create (RefClass(cComChilkatJsonObject)) To hoJObj
    If (Not(IsComObjectCreated(hoJObj))) Begin
        Send CreateComObject of hoJObj
    End
    Get pvComObject of hoJObj to vJObj
    Get ComObjectAt2 Of hoArr1 1 vJObj To iSuccess

    Get pvComObject of hoJObj to vJObj
    Get ComAddObjectCopyAt Of hoArr2 -1 vJObj To iSuccess

    Get ComEmit Of hoArr2 To sTemp1
    Showln sTemp1

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


End_Procedure