Sample code for 30+ languages & platforms
DataFlex

JSON AppendObjectCopy Example

Demonstrates the AppendObjectCopy function.

Note: This example requires Chilkat v9.5.0.82 or above.

Chilkat DataFlex Downloads

DataFlex
Use ChilkatAx-win32.pkg

Procedure Test
    Handle hoJson
    Boolean iSuccess
    Variant vJson2
    Handle hoJson2
    String sTemp1

    Get Create (RefClass(cComChilkatJsonObject)) To hoJson
    If (Not(IsComObjectCreated(hoJson))) Begin
        Send CreateComObject of hoJson
    End
    Get ComLoad Of hoJson '{ "name": "John", "marbles": 100 }' To iSuccess

    Get Create (RefClass(cComChilkatJsonObject)) To hoJson2
    If (Not(IsComObjectCreated(hoJson2))) Begin
        Send CreateComObject of hoJson2
    End
    Get ComLoad Of hoJson2 '{"street":"1200 Elm St.","city":"Springfield","zip":60606}' To iSuccess

    // Copy the contents of json2 to a new member object named "addr".
    Get pvComObject of hoJson2 to vJson2
    Get ComAppendObjectCopy Of hoJson "addr" vJson2 To iSuccess

    Get ComEmit Of hoJson To sTemp1
    Showln sTemp1
    // Expected output is:  {"name":"John","marbles":100,"addr":{"street":"1200 Elm St.","city":"Springfield","zip":60606}}

    // Note: Modifying the contents of json does not modify the contents of json2 (because the contents of json2 were copied).
    // For example:
    Get ComUpdateString Of hoJson "addr.street" "1000 Oak St." To iSuccess
    Get ComEmit Of hoJson To sTemp1
    Showln sTemp1
    // Expected output is:  {"name":"John","marbles":100,"addr":{"street":"1000 Oak St.","city":"Springfield","zip":60606}}

    Get ComEmit Of hoJson2 To sTemp1
    Showln sTemp1
    // Expected output is: {"street":"1200 Elm St.","city":"Springfield","zip":60606}


End_Procedure