Pascal (Lazarus/Delphi)
Pascal (Lazarus/Delphi)
Load JSON Data at Path
See more JSON Examples
Demonstrates how to load JSON data into a path within a JSON database. For example, we begin with this JSON:
{
"a": 1,
"b": 2,
"c": {
"x": 1,
"y": 2
}
}
Then we load {"mm": 11, "nn": 22} to "c", and the result is this JSON:
{
"a": 1,
"b": 2,
"c": {
"mm": 11,
"nn": 22
}
}
Chilkat Pascal (Lazarus/Delphi) Downloads
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
p: string;
json: TJsonObject;
q: string;
c: TJsonObject;
begin
// Demonstrates how to load replace the data at a location within a JSON database.
p := '{"a": 1, "b": 2, "c": { "x": 1, "y": 2 } }';
json := TJsonObject.Create;
json.Load(p);
json.EmitCompact := False;
WriteLn(json.Emit());
q := '{"mm": 11, "nn": 22}';
c := TJsonObject.Create;
json.ObjectOf2('c',c);
c.Load(q);
// See that x and y are replaced with mm and nn.
WriteLn(json.Emit());
json.Free;
c.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.