Skip to main content

GetChildDouble

function GetChildDouble(const aChildObjectName, aName: String;
const aDefault: Double): Double;

Example

procedure ScriptEvent(var Value: variant);
var
Payload: TJSONObject;
begin
Payload := TJSONObject.CreateFromString(
'{"totals":{"amount":12.5}}');
try
Value := Payload.GetChildDouble('totals', 'amount', 0.0);
finally
Payload.Free;
end;
end;

Usage

GetChildDouble converts a non-null nested value through locale-sensitive floating parsing or returns the required missing/null default.

Additional Technical Info

GetChildDouble performs a first case-insensitive lookup for an actual child object and a second for a non-null value. It returns the required aDefault only when the outer field is missing, null or not a TJSONObject, or the inner field is missing or null.

A present value is converted by TJSONValue.AsDouble, which calls Delphi StrToFloat(value.AsString) with process format settings. Dot-decimal JSON can therefore fail or be interpreted differently under a decimal-comma locale. Invalid, incompatible or out-of-range text raises EConvertError; the method does not fall back to aDefault after conversion starts.

Names select the first duplicate at each level. Lookups use FindValue and do not mutate the object. The returned Double can represent non-finite values even though JSON does not permit them.

External references

Created 2026-07-20