Unions shall be encoded as JSON objects as shown in Table 47.
Note that JSON objects are unordered sets of name-value pairs. The order specified by the DataTypeDefinition is not preserved when a Union is serialized in JSON.
Table 47 – JSON Object Definition for a Union
Name |
Description |
SwitchField |
This field is only present in the CompactEncoding. The identifier for the field in the Union which is encoded as a JSON number. The valid values for this field follow the conventions defined in 5.2.8. A Union with no field specified is encoded as an empty JSON object. |
<FieldName > |
The value of the field encoded using the rules that apply to the DataType. The name of field in the JSON object is the name of the field in the DataTypeDefinition.
|
For example, instances of the union:
struct Union1
{
Byte Selector;
{
Int32 A;
Double B;
Char* C;
}
Value;
};
would be represented in the CompactEncoding as:
{ "SwitchField":2, "B":3.1415 }
and would be represented in the VerboseEncoding as:
{ "B":3.1415 }