Genero BDL to JSON conversion rules

The JSON utility classes implement methods that can convert a Genero BDL RECORD or DYNAMIC ARRAY to a JSON data string. This topic describes how Genero BDL data is converted to JSON data.

To name the JSON elements, the names of the record members are used as defined in the program source. Since JSON is case-sensitive, make sure the names of the Genero BDL record members match exactly the names expected in the resulting JSON data string: CustNo will be different from custNo.
Important: JSON specifications allow you to define element names with characters that cannot be used in Genero BDL identifiers. For example, a JSON element name can be "customer.name" or "customer:name", however it is not possible to define a program variable with these same names. To work around this issue, define the record elements with underscores in place of unsupported characters, and before assigning the JSON string to the Genero BDL record, replace all element names by the corresponding record member names (using base.StringBuffer.replace to do the replacements).

When serializing a program variable with the util.JSON.stringify method, empty arrays and empty records (that is where all members are NULL) are written to the resulting string. To avoid empty elements in the JSON string, use the util.JSON.stringifyOmitNulls method instead.

Program array members in the record are converted to JSON arrays delimited by square brackets ([]).

Table 1. Genero BDL to JSON type conversion rules
Target Genero BDL type Description
BOOLEAN Will be serialized with the JSON values true or false.
TINYINT, SMALLINT, INTEGER, BIGINT, SMALLFLOAT, FLOAT, DECIMAL, MONEY Any numeric type will be serialized to this form: an optional minus sign (-), a sequence of digits (0-9), containing a optional decimal separator (.), followed by an optional exponent. The exponent has the form (e) followed by an optional minus sign and an sequence of digits. The representation of numeric values does not depend from the current locale. The decimal separator is always a dot (.). MONEY values will be represented like DECIMAL values: the currency symbol will be omitted.
DATE The date value will be formatted as "YYYY-MM-DD" (with double quotes)
DATETIME The date-time value will be formatted as "YYYY-MM-DD hh:mm:ss.fffff" (with double quotes), based on the date-time type definition. For example, a DATETIME HOUR TO MINUTE will produce "hh:mm" formatted values.

Note that the YYYY-MM-DD hh:mm:ss.ffff format is used to represent the local time. When exchanging date-time values in communications across different time zones, consider to convert date-time values to Coordinated Universal Time (UTC), by using the util.Datetime methods.

INTERVAL The interval value will be formatted as "YYYY-MM" or "DD hh:mm:ss.fffff" (with double quotes), depending on the interval type definition.
BYTE Will be serialized to a Base64 encoded double quoted string. The Base64 encoding is described in [RFC4648].
TEXT, CHAR, VARCHAR, STRING Character string data will be serialized as a double quoted string with backslash escaping.
List of characters requiring escaping:
  \\  backslash       U+005C
  \"  quotation mark  U+0022
  \b  backspace       U+0008
  \f  form feed       U+000C
  \n  line feed       U+000A
  \r  carriage return U+000D
  \t  tab             U+0009
Other Any other type will be serialized as a double quoted (") string.