4GL/JSON conversion rules

Certain rules are applied when 4gl variable are converted to/from JSON.

4GL to JSON conversion rules

Original 4GL datatype

Resulting JSON string

RECORD

a util.JSONObject in this form:

{ "record-element-name" : json-value [,...] }

DYNAMIC ARRAY

a util.JSONArray in this form:

[ json-value [,...] ]

BOOLEAN

a JSON TRUE or FALSE

TINYINT

SMALLINT

INTEGER

BIGINT

SMALLFLOAT

FLOAT

DECIMAL

MONEY

a sequence of characters in this form:

-{0..9}.exponent

Above and below, these are regular items, and these are optional ones

Exponents get this form:

e-{0..9}

Representation of numeric values does not depend on the current locale.

MONEY values are represented as DECIMAL values. Currency symbol is omitted.

Decimal separator is always . (dot) and never , (comma).

INTERVAL

is formatted as "YYYY-MM" or "DD hh:mm:ss.fffff" (in double quotes) depending on the definition of the interval type

BYTE

a Base64-encoded double-quoted string

TEXT

CHAR

VARCHAR

STRING

a double-quoted string with backslash escaping (if necessary)

These characters require 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

Values of any other datatype are converted to a double-quoted string.

JSON to 4GL conversion rules

Original JSON string

Resulting 4GL datatype

util.JSONObject in this form:

{ "record-element-name" : json-value [,...] }

RECORD

util.JSONArray in this form:

[ json-value [,...] ]

DYNAMIC ARRAY

JSON NULL, TRUE, or FALSE

If the JSON value is a number or a string, the rules are applied for converting number/string to BOOLEAN

BOOLEAN

JSON number

JSON numbers can be converted to a value of any numeric datatype.

Overflows errors may occur because of the limits of the target datatype. If any error occurs, the target variable will be initialized to NULL, and the parser will continue without errors.

TINYINT

SMALLINT

INTEGER

BIGINT

SMALLFLOAT

FLOAT

DECIMAL

MONEY

JSON string formatted as "YYYY-MM-DD"

DATE

JSON string representing a datetime or a JSON number

If the value is a JSON string, it must

  • be formatted as "YYYY-MM-DD hh:mm:ss.fffff", or
  • be an ISO8601-formatted datetime, in UTC (with Z) or with a timezone offset (+/-hh[:mm]) - e.g., "2018-04-05T1

If the value is a JSON number, it is interpreted as the UNIX™ time (in seconds since Unix epoch).

YYYY-MM-DD hh:mm:ss.ffff is used for local time.

When exchanging datetime values across different time zones, we recommend converting datetime values to Coordinated Universal Time (UTC) by the util.Datetime methods.

DATETIME

JSON string formatted as "YYYY-MM" or "DD hh:mm:ss.fffff", depending on the interval class of the target variable

INTERVAL

JSON string encoded in Base64

BYTE

JSON string or number

For JSON numbers, the resulting 4GL string will use the locale-specific decimal point.

For JSON strings,

  • 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.

  • characters outside the Basic Multilingual Plane may be escaped by their UTF-16 surrogate pairs - e.g., G-clef (U+1D11E) may be represented as "\uD834\uDD1E".

TEXT

CHAR

VARCHAR

STRING

 

Contact Us

Privacy Policy

Copyright © 2025 Querix, (UK) Ltd.