Skip to main content

AsString

property AsString: String read write;

Example

procedure ScriptEvent(var Value: variant);
var
Text: TJSONString;
Item: TJSONValue;
begin
Text := TJSONString.Create;
try
Item := Text;
Item.AsString := 'ready';
Value := Item.AsString;
finally
Text.Free;
end;
end;

Usage

AsString reads null-aware scalar text or compact JSON and writes through the class's parser or payload setter.

Additional Technical Info

The getter first calls virtual IsNull. If true, it returns '' without reading the retained payload. Otherwise it invokes the actual class's virtual raw getter:

Actual valueNon-null result
TJSONStringRaw unquoted Unicode text.
TJSONBooleanExact lowercase true or false.
TJSONIntegerSigned decimal text.
TJSONDoubleLocale-sensitive Delphi floating text.
TJSONArrayComplete compact array text.
TJSONObjectComplete compact object text.
TJSONNullAlways blank because its null getter is fixed true.

Array/object output allocates the complete document and inherits all documented serializer behavior: incomplete String/control escaping, unescaped object names, physical order/duplicates, locale-sensitive Double text, the empty-object } defect and array null-marked-scalar inconsistencies. This property returns serialization text for a container, not a borrowed internal buffer.

The setter invokes the concrete virtual raw setter. A String stores the supplied text. Boolean accepts only case-insensitive exact true/false; integer and Double use strict Delphi conversion; those scalar setters clear null state before parsing, so an invalid assignment can raise while leaving the old payload newly non-null. TJSONNull only changes an invisible base flag and remains null.

For an actual TJSONArray or TJSONObject, assignment parses a complete replacement document of the matching root kind. Parsing/wrong-root failure occurs before erasing current children, so prior content is retained. A successful matching parse deep-copies the new tree and invalidates old borrowed children. Empty/whitespace-only input produces no parsed source and also retains existing children. Parsing accepts the Deltics reader's documented nonstandard behaviors and ignores trailing content after the first value.

The operation is synchronous and unsynchronized. Scalar access is constant-time apart from String allocation/conversion; container reads/writes are proportional to the complete tree/text and can allocate another parsed/copy tree. Use IsNull before reading when null and empty text differ, and prefer typed properties only when the actual value contract is known.

External references

Created 2026-07-15