Sample code for 30+ languages & platforms
Unicode C

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 Unicode C Downloads

Unicode C
#include <C_CkJsonArrayW.h>
#include <C_CkJsonObjectW.h>

void ChilkatSample(void)
    {
    HCkJsonArrayW arr1;
    HCkJsonArrayW arr2;
    const wchar_t *s;
    const wchar_t *sEmpty;
    HCkJsonObjectW jObj;

    arr1 = CkJsonArrayW_Create();
    arr2 = CkJsonArrayW_Create();

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

    CkJsonArrayW_Load(arr1,s);
    CkJsonArrayW_Load(arr2,sEmpty);

    jObj = CkJsonObjectW_Create();
    CkJsonArrayW_ObjectAt2(arr1,1,jObj);

    CkJsonArrayW_AddObjectCopyAt(arr2,-1,jObj);

    wprintf(L"%s\n",CkJsonArrayW_emit(arr2));

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


    CkJsonArrayW_Dispose(arr1);
    CkJsonArrayW_Dispose(arr2);
    CkJsonObjectW_Dispose(jObj);

    }