Extension packages / The util package |
Describes how JSON data is converted to FGL data.
The JSON utility classes implement methods that can fill an FGL RECORD or DYNAMIC ARRAY. This topic describes how JSON data is converted to FGL data.
The destination record or array must have the same structure as the JSON source data.
Each JSON element is assigned to a record member by name, not by position. Elements in the JSON string can be at a different ordinal position as the corresponding members in the destination record.
Element names matching is case-insensitive. For example, if the FGL record member is defined as CustNo, and the JSON data string contains the "custno":999 name/value peer, the value will be assigned. However, since FGL record member names are used as is to write JSON data, is it strongly recommended to define the FGL records with the exact names used in JSON data string.
Elements in the JSON string that do not match an FGL record member are ignored (no error is thrown if there is no corresponding FGL member).
FGL record members that have no matching JSON element are initialized to NULL.
The JSON value must match the data format of the destination member, if the value does not correspond to the type (for example, if the JSON value is a character string while the target record member is defined with a numeric type), the target member will be set to NULL.
JSON arrays delimited by square brackets are used to fill a program array of the destination record. The destination array should be a dynamic array. If the array is defined as static, the additional elements of the source JSON array will be discarded, while missing elements will be initialized to NULL.
The JSON source string must follow the JSON format specification. It can contain multi-level structured data. If the source string is not well formatted, the runtime system will throw error -8109.
Target FGL type | Description |
---|---|
BOOLEAN | The JSON value should be null, true or false. If the JSON value is a number or a string, the language conversion rules from number/string to BOOLEAN apply. |
TINYINT, SMALLINT, INTEGER, BIGINT, SMALLFLOAT, FLOAT, DECIMAL, MONEY | A JSON number can be assigned to any language numeric type. The limits of the target type cause potential overflows errors. On error the target variable will be initialized to NULL, the parser continues without an error. |
DATE | The JSON string value must have the format "YYYY-MM-DD". |
DATETIME | If the value is a JSON string, it must be formatted as a Genero DATETIME variable. The string can also represent combined date and time in UTC as defined in ISO 8601. Example: 2013-02-21T15:18Z. If the value is a JSON number, it is interpreted as UNIX™ time (seconds since the Epoch 00:00:00 UTC, January 1, 1970). |
INTERVAL | The JSON string must be formated as an INTERVAL variable ("YYYY-MM" or "DD hh:mm:ss.fffff"). |
BYTE | The JSON string value must be encoded in base64. The base64 encoding is described in [RFC4648]. |
TEXT, CHAR, VARCHAR, STRING | If the value is a number, the result string uses the locale specific decimal point. Any character in the Basic Multilingual Plane (U+0000 through U+FFFF) may be escaped: \u followed by exactly 4 hexadecimal digits ([0-9a-fA-F]). The hexadecimal digits encode the code point. Escaping of characters outside the Basic Multilingual Plane my be escaped by there UTF-16 surrogate pairs. Example: This is the representation of the G clef character (U+1D11E) "\uD834\uDD1E". |