EventGridDeserializer class

EventGridDeserializer is used to aid in processing events delivered by EventGrid. It can deserialize a JSON encoded payload of either a single event or batch of events as well as be used to convert the result of JSON.parse into an EventGridEvent or CloudEvent like object.

Unlike normal JSON deseralization, EventGridDeserializer does some additional conversions:

  • The consumer parses the event time property into a Date object, for ease of use.
  • When deserializing an event in the CloudEvent schema, if the event contains binary data, it is base64 decoded and returned as an instance of the Uint8Array type.

Methods

deserializeCloudEvents(Record<string, unknown>)

Deserializes events encoded in the Cloud Events 1.0 schema.

deserializeCloudEvents(string)

Deserializes events encoded in the Cloud Events 1.0 schema.

Method Details

deserializeCloudEvents(Record<string, unknown>)

Deserializes events encoded in the Cloud Events 1.0 schema.

function deserializeCloudEvents(encodedEvents: Record<string, unknown>): Promise<CloudEvent<unknown>[]>

Parameters

encodedEvents

Record<string, unknown>

an object representing a single event, encoded in the Cloud Events 1.0 schema.

Returns

Promise<CloudEvent<unknown>[]>

deserializeCloudEvents(string)

Deserializes events encoded in the Cloud Events 1.0 schema.

function deserializeCloudEvents(encodedEvents: string): Promise<CloudEvent<unknown>[]>

Parameters

encodedEvents

string

the JSON encoded representation of either a single event or an array of events, encoded in the Cloud Events 1.0 Schema.

Returns

Promise<CloudEvent<unknown>[]>