Unions shall be encoded as JSON objects as shown in Table 44 for the reversible encoding.

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. The SwitchField may not appear as the first field.

Table 44 – JSON Object Definition for a Union

Name

Description

SwitchField

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.

If the SwitchField value is its DefaultValue of 0, then the SwitchField and the Value field are not present.

Value

The value of the field encoded using the rules that apply to the data type.

For the non-reversible form, Union values are encoded using the rule for the current value. If the SwitchField is 0 the Union is encoded as a JSON null value.

For example, instances of the union:

struct Union1

{

Byte Selector;

{

Int32 A;

Double B;

Char* C;

}

Value;

};

would be represented in reversible form as:

{ "SwitchField":2, "Value":3.1415 }

In non-reversible form, it is represented as:

3.1415