Variant Objects
A variant object is a JSON object that functions as a standard representation of any type of value because it contains key information including its value, type, value encoding, and storage encoding. Any application can use it to exchange data reliably. FairCom uses it in its JSON API to represent data types that JSON does not support, such as binary data. It has up to five properties: "schema", "value", "type", "valueEncoding", and "storageEncoding".
The variant object requires the "schema", "value", and "type" properties.
- The value of the
"schema"property is always set to"jsonaction.org/schemas/variantObject", which uniquely identifies a JSON object as a variant object. - When sending a variant object to the server, the server converts the value in the
"value"property to the type specified in the"type"property and stores the converted value. - When receiving a variant object from the server, the
"type"property tells the application the type of the variant value. This is important because JSON cannot represent many types of values, including binary values, images, dates, etc. For example, the"value"property may be assigned to a string and inside the string may be Base64 value representing a PNG image.
Example variant object
{
"schema": "jsonaction.org/schemas/variantObject",
"value": "-123",
"type": "number",
"valueEncoding": [],
"storageEncoding": ["bigint"]
}
Variant object properties
| Property | Description | Default | Type | Limits (inclusive) |
|---|---|---|---|---|
value |
The When the type is This example shows a JSON object being assigned to the { |
Required - No default value | JSON value |
|
type |
The Each type has a unique name. See List of Variant Types for the complete list. The following example is a variant object containing a PNG image encoded as Base64. {
"schema": "jsonaction.org/schemas/variantObject",
"value": "77+9UE5HChoKAAAACklIRFIAAAABAAAAAQgCAAAA77+9d1Pvv70AAAAMSURBVHjvv71jYGBgAAAABAAB77+9FzhVAAAAAElFTkTvv71CYO+/vQ==",
"type": "png",
|
Required - No default value | enum |
Fundamental types
Document types
Code types
Data types
Image types
Video types
Audio types
Music types
Font types
|
valueEncoding |
The The following example encodes the text {
"schema": "jsonaction.org/schemas/variantObject",
"value": "486921",
"type": "binary", |
Optional with default of []
|
array |
|
storageEncoding |
The The following example encodes the text |
Optional with default of []
|
array |
["tinyint"]["smallint"]["integer"]["bigint"]["float"]["double"]["numeric"]
|