Delphi DLL
Delphi DLL
Pretty Print JSON (Formatter, Beautifier)
See more JSON Examples
Demonstrates how to emit JSON in a pretty, human-readable format with indenting of nested arrays and objects.Chilkat Delphi DLL Downloads
uses
Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls, JsonObject;
...
procedure TForm1.Button1Click(Sender: TObject);
var
success: Boolean;
json: HCkJsonObject;
jsonStr: PWideChar;
begin
success := False;
json := CkJsonObject_Create();
jsonStr := '{"name": "donut","image":{"fname": "donut.jpg","w": 200,"h": 200},"thumbnail":{"fname": "donutThumb.jpg","w": 32,"h": 32}}';
success := CkJsonObject_Load(json,jsonStr);
if (success <> True) then
begin
Memo1.Lines.Add(CkJsonObject__lastErrorText(json));
Exit;
end;
// To pretty-print, set the EmitCompact property equal to False
CkJsonObject_putEmitCompact(json,False);
// If bare-LF line endings are desired, turn off EmitCrLf
// Otherwise CRLF line endings are emitted.
CkJsonObject_putEmitCrLf(json,False);
// Emit the formatted JSON:
Memo1.Lines.Add(CkJsonObject__emit(json));
CkJsonObject_Dispose(json);
end;