Sample code for 30+ languages & platforms
Pascal (Lazarus/Delphi)

JSON PathPrefix Example

Demonstrates the JSON object's PathPrefix property.

Chilkat Pascal (Lazarus/Delphi) Downloads

Pascal (Lazarus/Delphi)
program ChilkatDemo;

// Demonstrates using the Chilkat Pascal wrapper via the C bridge DLL.
// Builds as a console application under Lazarus (FPC) or Delphi.

{$IFDEF FPC}
  {$MODE DELPHI}
{$ENDIF}
{$APPTYPE CONSOLE}

uses
  {$IFDEF UNIX}
  cthreads,
  {$ENDIF}
  SysUtils,
  CkDllLoader,
  Chilkat.JsonObject;

// ---------------------------------------------------------------------------

procedure RunDemo;
var
  success: Boolean;
  json: TJsonObject;
  city: string;

begin
  success := False;

  json := TJsonObject.Create;

  json.PathPrefix := 'company.billing.';

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

  json.EmitCompact := False;

  WriteLn(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"
  //      }
  //    }
  //  }

  city := json.StringOf('city');
  WriteLn('city = ' + city);


  json.Free;

end;

// ---------------------------------------------------------------------------

begin

  try
    RunDemo;
  except
    on E: Exception do
      WriteLn('Unhandled exception: ', E.ClassName, ': ', E.Message);
  end;

  WriteLn;
  {$IFDEF MSWINDOWS}
  WriteLn('Press Enter to exit...');
  ReadLn;
  {$ENDIF}
end.