Sample code for 30+ languages & platforms
Unicode C++

JSON PathPrefix Example

Demonstrates the JSON object's PathPrefix property.

Chilkat Unicode C++ Downloads

Unicode C++
#include <CkJsonObjectW.h>

void ChilkatSample(void)
    {
    bool success = false;

    CkJsonObjectW json;

    json.put_PathPrefix(L"company.billing.");

    json.UpdateString(L"company_name",L"TechNova Solutions Inc.");
    json.UpdateString(L"address_line_1",L"123 Innovation Drive");
    json.UpdateString(L"address_line_2",L"Suite 450");
    json.UpdateString(L"city",L"Seattle");
    json.UpdateString(L"state_province",L"WA");
    json.UpdateString(L"postal_code",L"98101");
    json.UpdateString(L"country",L"USA");

    json.put_EmitCompact(false);

    wprintf(L"%s\n",json.emit());

    // Result:

    // {
    //   "company": {
    //     "billing": {
    //       "company_name": "TechNova Solutions Inc.",
    //       "address_line_1": "123 Innovation Drive",
    //       "address_line_2": "Suite 450",
    //       "city": "Seattle",
    //       "state_province": "WA",
    //       "postal_code": "98101",
    //       "country": "USA"
    //     }
    //   }
    // }

    const wchar_t *city = json.stringOf(L"city");
    wprintf(L"city = %s\n",city);
    }