The JSON Format for Cloud Native Events defines how events are expressed in JavaScript Object Notation (JSON) Data Interchange Format (RFC8259).
Cloud Native Events is a standardized and protocol-agnostic definition of the structure and metadata description of events for cloud applications. This specification defines how the elements defined in the Cloud Native Events specification are to be represented in the JavaScript Object Notation (JSON) Data Interchange Format (RFC8259).
The key words "MUST", "MUST NOT", "REQUIRED", "SHALL", "SHALL NOT", "SHOULD", "SHOULD NOT", "RECOMMENDED", "MAY", and "OPTIONAL" in this document are to be interpreted as described in RFC2119.
The Cloud Native Events type system MUST be mapped to JSON types as follows, with exceptions noted below.
Cloud Native Events | JSON |
---|---|
Boolean | boolean |
Integer | number, only the int component is permitted |
String | string |
URI | string following RFC 3986 |
URI-reference | string following RFC 3986 |
Timestamp | string following RFC 3339 (ISO 8601) |
Unset attributes MAY be encoded to the JSON value of null
. When decoding
attributes and a null
value is encountered, it MUST be treated as the
equivalent of unset or omitted.
Extension specifications MAY define secondary mapping rules for the values of attributes they define, but MUST also include the previously defined primary mapping.
For instance, the attribute value might be a data structure defined in a standard outside of Cloud Native Events, with a formal JSON mapping, and there might be risk of translation errors or information loss when the original format is not preserved.
An extension specification that defines a secondary mapping rule for JSON, and any revision of such a specification, MUST also define explicit mapping rules for all other event formats that are part of the Cloud Native Events core at the time of the submission or revision.
If required, like when decoding Maps, the Cloud Native Events type can be determined by
inference using the rules from the mapping table, whereby the only potentially
ambiguous JSON data type is string
. The value is compatible with the
respective Cloud Native Events type when the mapping rules are fulfilled.
The following table shows exemplary attribute mappings:
Cloud Native Events | Type | Exemplary JSON Value |
---|---|---|
type | String | "com.example.someevent" |
specversion | String | "1.0" |
id | String | "1234-1234-1234" |
id | String | null |
time | Timestamp | "2018-04-05T17:31:00Z" |
time | Timestamp (null) | null |
data | array |
The Cloud Native Events JSONSchema for the spec is located here and contains the definitions for validating events in JSON.
An example of an empty batch of Cloud Native Events (typically used in a response, but also valid in a request):
[]
- RFC2046 Multipurpose Internet Mail Extensions (MIME) Part Two: Media Types
- RFC2119 Key words for use in RFCs to Indicate Requirement Levels
- RFC4627 The application/json Media Type for JavaScript Object Notation (JSON)
- RFC4648 The Base16, Base32, and Base64 Data Encodings
- RFC6839 Additional Media Type Structured Syntax Suffixes
- RFC8259 The JavaScript Object Notation (JSON) Data Interchange Format