Sample code for 30+ languages & platforms
Unicode C

JSON AppendObject2 Example

Demonstrates the AppendObject2 function.

Chilkat Unicode C Downloads

Unicode C
#include <C_CkJsonObjectW.h>

void ChilkatSample(void)
    {
    HCkJsonObjectW json;
    HCkJsonObjectW jObj;

    json = CkJsonObjectW_Create();
    CkJsonObjectW_Load(json,L"{ \"name\": \"John\", \"marbles\": 100 }");

    //  Append an empty object named "addr"
    jObj = CkJsonObjectW_Create();
    CkJsonObjectW_AppendObject2(json,L"addr",jObj);

    wprintf(L"%s\n",CkJsonObjectW_emit(json));
    //  Expected output is:   {"name":"John","marbles":100,"addr":{}}

    //  Add members to the object.
    CkJsonObjectW_AppendString(jObj,L"street",L"1200 Elm St.");
    CkJsonObjectW_AppendString(jObj,L"city",L"Springfield");
    CkJsonObjectW_AppendInt(jObj,L"zip",60606);

    wprintf(L"%s\n",CkJsonObjectW_emit(json));
    //  Expected output is:  {"name":"John","marbles":100,"addr":{"street":"1200 Elm St.","city":"Springfield","zip":60606}}


    CkJsonObjectW_Dispose(json);
    CkJsonObjectW_Dispose(jObj);

    }