Sign in Join
FPDoc Onlineexperiment

ValueToJSON function

In unit fpJsonValue

Converts a TValue to a JSON data structure

Declaration

pascal
function ValueToJSON(const aValue: TValue; aType: TRttiType): TJSONData

Arguments

aValue

The TValue record to convert to JSON

aType

The RTTI type information for the value being converted

Function result

The JSON data structure representing the converted value

Description

ValueToJSON converts a TValue record to its corresponding JSON representation using the provided RTTI type information. The function supports conversion of strings (AnsiString, UnicodeString, WideString, ShortString), integers (Integer, Int64, QWord), booleans, and dynamic arrays. For dynamic arrays, the function recursively converts each element using the array's element type information. If an error occurs during conversion, any partially created JSON structure is cleaned up before re-raising the exception.

Errors

May raise an exception if the conversion fails or if an unsupported type is encountered.

See also

An experiment, built from development snapshots. Not the official Free Pascal or Lazarus documentation.