Normalizing JSON maps
- Last Updated: July 22, 2024
- 2 minute read
- DataDirect Connectors
- JDBC
- Autonomous REST Connector 6.0
- Documentation
- The keys must me be one of the following types:
- Numeric values
- GUIDs
- Dates formatted as YYYY-MM-DD
- Times using the ISO 8061 format. The map may contain values with and without timezones in the same map.
- Timestamps using the ISO 8061 format. The map may contain values with and without timezones in the same map.
- Every key in the object must be of the same type.
For example, the following JSON document contains a map that uses dates as keys:
{
"1979-10-31":{"attendance":"12080","opponent":"Wildcats","result":"loss"},
"1979-12-06":{"attendance":"34000","opponent":"Mustangs","result":"loss"},
"1979-11-06":{"attendance":"8500","opponent":"Jets","result":"loss"},
}
When mapping the schema, the driver normalizes the key-value pairs in the JSON
map to a child table. The fields in the map value are mapped into relational columns.
For example, the attendance and opponent fields, are
mapped to relational columns with corresponding names. Similarly, the key portion of the
key-value pair is mapped to the KEY column by default. The primary key
is determined by the type of the key column. For key values that are numeric values or
GUIDS, the KEY column is used as the primary key. For key values that
are date, time, or timestamp values, the driver generates primary keys in the
ROWID column to avoid the possibility of non-unique primary keys
(See “Determining the primary key” for more information).
The name of the parent table is derived from the endpoint from which the data
was sampled. The parent table for our example is named SEASON_RESULTS and takes the following form:
| KEY (PK) | ATTENDANCE | OPPONENT | RESULT |
|---|---|---|---|
| 1979-10-31 | 12080 | Wildcats | loss |
| 1979-12-06 | 34000 | Mustangs | loss |
| 1979-11-06 | 8500 | Jets | loss |