# Message

> 

On `message` [hook](/guide/hooks), you receive a message object containing data from the client.

<note>

Message object is API-compatible with standard Websocket [`MessageEvent`](https://developer.mozilla.org/en-US/docs/Web/API/WebSocket/message_event) with convenient superset of utils.

</note>

## Instance properties

### `message.id`

Unique random identifier ([uuid v4](https://developer.mozilla.org/en-US/docs/Glossary/UUID)) for the message.

### `message.event`

Access to the original [message event](https://developer.mozilla.org/en-US/docs/Web/API/WebSocket/message_event) if available.

### `message.peer`

Access to the [peer instance](/guide/peer) that emitted the message.

### `message.rawData`

Raw message data (can be of any type).

### `message.data`

Message data (value varies based on [`peer.binaryType`](/guide/peer#peerbinarytype)).

## Instance methods

### `message.text()`

Get stringified text version of the message.

If raw data is in any other format, it will be automatically converted or decoded.

### `message.json()`

Get parsed version of the message text with [`JSON.parse()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/parse).

<tip>

You can optionally use [`unjs/destr`](https://github.com/unjs/destr) to safely parse the message object.

It does not throw an error if the input is not valid JSON but falls back to text and also removes any fields that could potentially cause prototype pollution vulnerabilities.

```ts
const data = destr(await message.text());
```

</tip>

### `message.uint8Array()`

Get data as [`Uint8Array`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Uint8Array) value.

If raw data is in any other format or string, it will be automatically converted or encoded.

### `message.arrayBuffer()`

Get data as [`ArrayBuffer`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ArrayBuffer) or [`SharedArrayBuffer`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/SharedArrayBuffer) value.

If raw data is in any other format or string, it will be automatically converted or encoded.

### `message.blob()`

Get data as [`Blob`](https://developer.mozilla.org/en-US/docs/Web/API/Blob) value.

If raw data is in any other format or string, it will be automatically converted or encoded.

## Adapter support

<table>
<thead>
  <tr>
    <th>
      
    </th>
    
    <th>
      <a href="/adapters/bun">
        Bun
      </a>
    </th>
    
    <th>
      <a href="/adapters/cloudflare">
        Cloudflare
      </a>
    </th>
    
    <th>
      <a href="/adapters/cloudflare#durable-objects">
        Cloudflare (durable)
      </a>
    </th>
    
    <th>
      <a href="/adapters/deno">
        Deno
      </a>
    </th>
    
    <th>
      <a href="/adapters/node">
        Node (ws)
      </a>
    </th>
    
    <th>
      <a href="/adapters/node#uwebsockets">
        Node (μWebSockets)
      </a>
    </th>
    
    <th>
      <a href="adapters/sse">
        SSE
      </a>
    </th>
  </tr>
</thead>

<tbody>
  <tr>
    <td>
      <code>
        event
      </code>
    </td>
    
    <td>
      ⨉
    </td>
    
    <td>
      ✓
    </td>
    
    <td>
      ⨉
    </td>
    
    <td>
      ✓
    </td>
    
    <td>
      ⨉
    </td>
    
    <td>
      ⨉
    </td>
    
    <td>
      ⨉
    </td>
  </tr>
</tbody>
</table>
