# JsonSocketOptions

**Kind:** Interface

**Source:** [`packages/microservices/helpers/json-socket.ts`](https://github.com/nestjs/nest/blob/master/packages/microservices/helpers/json-socket.ts#L9)

**Part of:** [Microservices](subsystem-packages-microservices)

`JsonSocketOptions` configures buffering behavior for the JSON socket helper used by the microservices transport layer. Its `maxBufferSize` property defines the maximum amount of incoming data that may be buffered while assembling and parsing JSON messages.

## Properties

| Property | Type |
|---|---|
| `maxBufferSize` | `number` |

## Diagram

```mermaid
graph LR
  Client[Socket Client] --> Socket[JSON Socket]
  Socket --> Buffer[Incoming Data Buffer]
  Buffer --> Limit[maxBufferSize]
  Limit --> Parser[JSON Message Parser]
  Parser --> Handler[Microservice Handler]
```

## Usage

```ts
import { JsonSocketOptions } from './helpers/json-socket';

const socketOptions: JsonSocketOptions = {
  // Limit buffered incoming socket data to 1 MB.
  maxBufferSize: 1024 * 1024,
};

// Pass the options when creating or configuring the JSON socket.
const jsonSocket = new JsonSocket(socket, socketOptions);
```

## AI Coding Instructions

- Set `maxBufferSize` to a value appropriate for expected message sizes and available memory.
- Treat this limit as a safety boundary against malformed, incomplete, or excessively large socket payloads.
- Keep the value in bytes and document any non-default limits used by a transport configuration.
- Ensure socket integrations handle buffer-limit failures by closing, resetting, or reporting invalid connections as appropriate.
