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

JSON UpdateString

See more JSON Examples

Demonstrates the JSON object's UpdateString method.

Note: The UpdateString method was introduced in Chilkat v9.5.0.63

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
  json: TJsonObject;

begin
  //  This example requires Chilkat v9.5.0.63 or greater.

  json := TJsonObject.Create;
  json.EmitCompact := False;

  //  The UpdateString method updates or adds a string member.
  //  It also auto-creates the objects and/or arrays that
  //  are missing.  For example:
  json.UpdateString('test.abc[0].xyz','Chicago Cubs');

  //  The JSON now contains:
  WriteLn(json.Emit());

  //  {
  //    "test": {
  //      "abc": [
  //        {
  //          "xyz": "Chicago Cubs"
  //        }
  //      ]
  //    }

  json.UpdateString('test.abc[0].xyz','Chicago Cubs are going to win the World Series!');
  WriteLn(json.Emit());

  //  {
  //    "test": {
  //      "abc": [
  //        {
  //          "xyz": "Chicago Cubs are going to win the World Series!"
  //        }
  //      ]
  //    }


  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.