Data type mapping
- Last Updated: October 17, 2024
- 2 minute read
- OpenEdge
- Version 12.8
- Documentation
Data type mapping
In JSON basics, you saw that JSON uses only a few primitive data types. In addition, the JSON community has created a few non-standard data types to cover a few other common data types.
The following table shows the non-standard JSON data types that ABL supports.
| Data type | JSON representation |
|---|---|
| Date-time | A JSON string in the ISO 8601 format,
"yyyy-mm-ddThh:mm:ss.sss+hh:mm" |
| Binary data | A JSON string consisting of the Base64 encoded equivalent of the binary data |
For serializing ABL data objects to JSON strings, only the ABL data types
that you can assign to a temp-table field are mapped to JSON data types. The exception to this
is the ABL CLASS data type. The ABL serialization features
support serializing fields with data types based on ABL class definitions if the class and all
the classes in its hierarchy are marked as SERIALIZABLE.
The following table shows how the AVM maps ABL data types to JSON data types.
We only support JsonObject and JsonArray as types.These
mappings apply when the AVM writes ABL data to JSON and when the AVM reads JSON data into an
ABL data object with a defined schema. Class-based objects cannot be added to a
JsonObject or JsonArray.
| ABL data type | JSON data type |
|---|---|
BLOB
|
string (Base64 encoded) |
CHARACTER
|
string |
| Class-based object | Object |
CLOB
|
string |
COM-HANDLE
|
number |
DATE
|
string (ISO 8601 formatted string of
the form "yyyy-mm-dd") |
DATETIME
|
string (ISO 8601 formatted string of
the form "yyyy-mm-ddThh:mm:ss.sss") |
DATETIME-TZ
|
string (ISO 8601 formatted string of
the form "yyyy-mm-ddThh:mm:ss.sss+hh:mm") |
DECIMAL
|
number |
HANDLE
|
number |
INT64
|
number |
INTEGER
|
number |
LOGICAL
|
boolean (true or
false) |
RAW
|
string (Base64 encoded) |
RECID
|
number |
ROWID
|
string (Base64 encoded) |
When parsing values to or from JSON, the AVM equates the ABL Unknown value
(?) to a JSON null value.
If a JSON string's value is too long for the ABL data type, the
AVM generates an error message and the READ-JSON( ) method
returns FALSE.
If a JSON number's value is out of the ABL data type's range, the
AVM generates an error message and the READ-JSON( ) method
returns FALSE.
If you read JSON data into an ABL data object that has a schema, the AVM
assumes that the JSON values are formatted appropriately for the data object's schema. For
example, if the AVM reads JSON data into an ABL temp-table field of the DATETIME data type, the AVM assumes that the value is a string in
the ISO 8601 format. If the JSON value cannot be converted to the expected ABL data type,
READ-JSON( ) generates an error message and returns FALSE.
If you read a JSON string into a dynamic ABL data object that does not have a schema, the AVM
infers the schema from the JSON data. When you read JSON into an ABL data object with an
inferred schema, the AVM uses different rules to assign ABL data types to JSON values. With
the inferred data types, the AVM makes no attempt to determine if the JSON values represent
one of the non-standard data types. For example, all quoted values are mapped to the
CHARACTER data type. For more information about inferring schema, see Infer ABL schemas from JSON data.