Skip to main content

AddGUID

function AddGUID(const aValue: TGUID): TJSONString;

Example

procedure ScriptEvent(var Value: variant);
var
Values: TJSONArray;
begin
Values := TJSONArray.Create;
try
Values.AddGUID(StringToGUID('{12345678-1234-1234-1234-1234567890AB}'));
Value := Values.AsString;
finally
Values.Free;
end;
end;

Usage

AddGUID appends a braced GUID string, while the all-zero GUID triggers the empty-string null defect.

Additional Technical Info

For a nonzero TGUID, AddGUID creates an owned string node containing Delphi GUIDToString output, including braces. JSON has no native UUID type; this is a Velox/Deltics string convention and a consumer may require braces to be removed or a different case.

The all-zero GUID is treated as null by marking a TJSONString with IsNull=True. Because the array serializer tests its string value type before its null flag, it emits "" rather than JSON null. Handle the zero-GUID policy explicitly.

The returned node is borrowed from the owning array. Do not free it; deletion, erase, content replacement or parent destruction invalidates it. Parsing a value back through AsGUID can raise if remote text is malformed.

External references

Created 2026-07-20