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

Create JSON Document

See more JSON Examples

Sample code to create the following JSON document:
{
  "Title": "Pan's Labyrinth",
  "Director": "Guillermo del Toro",
  "Original_Title": "El laberinto del fauno",
  "Year_Released": 2006
}

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;

begin
  success := False;

  json := TJsonObject.Create;

  //  The only reason for failure in the following lines of code would be an out-of-memory condition..

  //  An index value of -1 is used to append at the end.
  success := json.AddStringAt(-1,'Title','Pan''s Labyrinth');
  success := json.AddStringAt(-1,'Director','Guillermo del Toro');
  success := json.AddStringAt(-1,'Original_Title','El laberinto del fauno');
  success := json.AddIntAt(-1,'Year_Released',2006);

  json.EmitCompact := False;
  WriteLn(json.Emit());


  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.