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

Create JSON Array of Strings

See more JSON Examples

Demonstrates how to create a JSON array of strings.

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.JsonArray;

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

procedure RunDemo;
var
  jarr: TJsonArray;

begin
  //  The goal of this example is to produce this:

  //  [
  //    "tag1",
  //    "tag2",
  //    "tag3"
  //  ]

  jarr := TJsonArray.Create;
  jarr.AddStringAt(-1,'tag1');
  jarr.AddStringAt(-1,'tag2');
  jarr.AddStringAt(-1,'tag3');

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


  jarr.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.