TJSONValueType
TJSONValueType = (jsString, jsNumber, jsBoolean, jsArray, jsObject, jsNull)
Example
procedure ReadJSONValue(Item: TJSONValue; var Value: Variant);
begin
if Item.ValueType = jsNull then
Value := Null
else if Item.ValueType = jsString then
Value := Item.AsString
else
Value := Item.AsInfo;
end;
Usage
TJSONValueType reports the JSON value class as string, number, Boolean, array, object or null.
Members
| Value | Ordinal | Meaning |
|---|---|---|
jsString | 0 | A TJSONString, with separate mutable null state and incomplete escape handling. |
jsNumber | 1 | A TJSONInteger or TJSONDouble, with exponent/locale limitations. |
jsBoolean | 2 | A TJSONBoolean. |
jsArray | 3 | An owned ordered TJSONArray. |
jsObject | 4 | An owned named-value TJSONObject, including lookup/serialization quirks. |
jsNull | 5 | A TJSONNull that always reports null. |
Behavior and boundaries
ValueTypeis class-derived and read-only. AssigningIsNull := Trueon an ordinary value does not change itsValueTypetojsNull; test both when null-state provenance matters.AsArrayandAsObjectuse Velox checked class casts and raise for the wrong kind.- Several scalar accessors accept more than one kind by converting
AsString; locale, format, overflow and invalid-text errors can still occur. AsBooleanreturns false for null; non-Boolean values compare their text case-insensitively withtrue. This can conceal malformed Boolean input unlessValueTypeis checked first.- Objects and arrays require traversal; do not serialize or compare them as if
AsStringwere a normalized scalar representation.
Parser and serializer limits
- Literal
true,falseandnullinput is accepted case-insensitively, outside RFC 8259's lowercase grammar. \uescapes are not decoded: theuand four hexadecimal digits all remain text.- Exponent-only numbers are misclassified as integers; double parsing/formatting uses host-locale
StrToFloat/FloatToStr. - Empty-object compact
AsStringreturns}and property names are not JSON-escaped. Other uncommon control characters can also be emitted unescaped. TJSONObject.Values[missing]adds a named null, so a lookup can mutate the object. Lookup is case-insensitive first-match and duplicate names are permitted.- Scalar
Clearmarks null without erasing stored data; arrays/objects always report non-null.
Additional Technical Info
TJSONValueType is assigned by the base TJSONValue constructor from the concrete runtime class. It identifies JSON syntax kind, allowing scripts to select a compatible accessor before conversion.
The constructor recognizes array, string, Boolean, null, number and object subclasses. An unknown direct subclass raises EJSONError rather than receiving a fallback enum value.
Related Code Library entries
- TJSONValue.ValueType - exact constructor-derived property.
- TJSONValue.IsNull - separate mutable null flag.
- TJSONValue.AsArray - checked array cast.
- TJSONValue.AsObject - checked object cast.
External references
- RFC 8259 JSON values - standard JSON value kinds.
- Embarcadero enumerated types - Delphi ordinal semantics.
- Free Pascal ordinal types - compatible enumeration concepts.