DUECA/DUSIME
|
JSON is a commonly used data communication format. This chapter describes how DCO objects are converted into JSON.
A JSON object describes data as label - value pairs. Since the value in such a pair can contain another JSON object, complex nested data structures can be represented. There can be several uses for a JSON representation of a DUECA DCO objects. The simplest is for communication with some external code that does not want to, or is not able to, use the DCO packing/unpacking mechanisms.
If the structure of the DCO object is known to that code, only packing the data, with variable names as label, is sufficient for communication. This results in a compact mode for coding a DCO object. If the structure of the DCO object is not known, or you want to record the data in a more robust manner, the JSON packaging can mix both class and datatype information from the DCO object, and the values in the DCO object, in an extended mode.
The following logic is used for compact packing of a DCO object in JSON:
single-element data is packed with a label equal to the element name and the value equal to the element value. If the value is in itself a DCO object, this results in a nested JSON object. This is also valid for the iterable types.
iterable data is packed with a label equal to the element name, and the values as an array.
map data, which is iterable data with key values, is packed as an array with JSON objects, which have a "key" and "value" element. Note that this result would be identical for a normal iterable (list, vector), of a DCO object with a key and value member; you need to know the DCO object type to properly unpack the data.
Here is an (incomplete) example for the DCO object structure:
Let's suppose there are three elements in the map. The compact JSON translation would look like:
In the extended mode, the JSON object also contains information about the data class.
The following logic is used for extended packing of a DCO object in JSON:
The class name is packed with the label "class"
If the class is derived from another dcoclass, the JSON has a label "parent", which contains another extended packing, in this case of the parent and its data.
Data are coded in a list of JSON objects denoted by the label members
Each member object has the following
Here is an example of the same object, now coded with extended information
Until now, the extended mode is a plan only, it has not been implemented.