Skip to main content

AsBoolean

property AsBoolean: Boolean read write;

Example

procedure ScriptEvent(var Value: variant);
var
Text: TJSONString;
Item: TJSONValue;
begin
Text := TJSONString.Create;
try
Item := Text;
Item.AsString := 'TRUE';
Value := Item.AsBoolean; // True; comparison is case-insensitive.
finally
Text.Free;
end;
end;

Usage

AsBoolean reads an actual Boolean or exact true text and writes lowercase Boolean text through the value setter.

Additional Technical Info

For an actual non-null TJSONBoolean, the reader returns its stored native value. For every other non-null class it compares AsString with the exact word true using case-insensitive SameText. There is no trimming or alternative truth syntax: ' TRUE ', '1', 'yes', arrays and objects all read False. A null value reads False, so check IsNull when false and null must differ.

Writing maps True to lowercase true and False to lowercase false, then assigns that text through the receiver's virtual String setter. This stores a Boolean payload on TJSONBoolean and literal text on TJSONString. Other actual classes follow their own parsers: numeric conversion raises, an object/array parser rejects the scalar root before erasing existing children, and TJSONNull remains observably null. Use the property for Boolean/String nodes whose contract is known, not as a generic type conversion target.

TJSONBoolean.DoSetAsString marks the node non-null before validating the text. Although this property's own generated text is always valid, related direct String assignments can raise after clearing null state and retain the old Boolean field. Reads/writes are synchronous and locale-independent.

External references

Created 2026-07-15